HW02 運算子表達式
HW02 運算子表達式
Kilogram to Pound and Tonne Converter 🐍
📌 Description
This Python program reads the weight of an object in kilograms and converts it into pounds and tonnes. It uses simple arithmetic operations to calculate the converted weights.
🎯 Objective
To write a Python program that accepts weight in kilograms and displays the equivalent weight in pounds and tonnes.
📐 Conversion Formula
1 Kilogram = 2.20 Pounds
1 Kilogram = 0.001 Tonne
💻 Python Code
weight = int(input('Enter the weight of object in kilogram:'))
pounds = weight * 2.20
Tonne = weight * 0.001
print(' Weight = ', weight, ' Kilograms')
print(weight, ' kg = %.2f' % (pounds), ' pounds')
print(weight, ' kg = %.2f' % (Tonne), ' Tonne')▶️ Sample Output
Enter the weight of object in kilogram: 100
Weight = 100 Kilograms
100 kg = 220.00 pounds
100 kg = 0.10 Tonne🧠 How It Works
The program asks the user to enter the weight in kilograms.
It multiplies the weight by
2.20to calculate pounds.It multiplies the weight by
0.001to calculate tonnes.It displays the original weight and the converted values to two decimal places.
🛠️ Requirements
Python 3.x
Any Python editor or IDE, such as VS Code, IDLE, or PyCharm.
🚀 How to Run
Clone this repository or download the Python file.
Open a terminal in the project directory.
Run the following command:
python weight_converter.pyEnter the weight in kilograms when prompted.
📚 Concepts Used
User input with
input()Type conversion using
int()Arithmetic operations
Output










留言
張貼留言