HW02 運算子表達式

  HW02 運算子表達式

2. 影片
3. 測驗和學習卡













4. 

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

  1. The program asks the user to enter the weight in kilograms.

  2. It multiplies the weight by 2.20 to calculate pounds.

  3. It multiplies the weight by 0.001 to calculate tonnes.

  4. 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

  1. Clone this repository or download the Python file.

  2. Open a terminal in the project directory.

  3. Run the following command:

    python weight_converter.py
  4. Enter the weight in kilograms when prompted.

📚 Concepts Used

  • User input with input()

  • Type conversion using int()

  • Arithmetic operations

  • Output


留言

這個網誌中的熱門文章