This Python program receives the weight of a product in kilograms and converts it to grams.
By definition, 1 kilogram = 1000 grams.
# Get weight in kilograms from user
kg = float(input("Enter the weight in kilograms: "))
# Convert to grams
grams = kg * 1000
# Display result
print("\n--- Result ---")
print(f"The weight is: {grams:.2f} grams")
Enter the weight in kilograms: 2.5
--- Result ---
The weight is: 2500.00 grams
- The input weight is received using input() and converted to a float
- The weight in grams is calculated by multiplying the kilogram value by 1000
- The result is displayed with two decimal places for clarity