Part of the series

Several example codes

~1 min read • Updated Sep 29, 2025

Program Overview

This Python program receives the weight of a product in kilograms and converts it to grams.
By definition, 1 kilogram = 1000 grams.


Python Code:


# 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")

Sample Output:


Enter the weight in kilograms: 2.5  

--- Result ---  
The weight is: 2500.00 grams

Explanation:

- 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


Written & researched by Dr. Shahin Siami