INTRODUCTION
The Unit Converter is a Python-primarily based application that helps customers convert temperature and weight measurements. It affords a menu-pushed interface wherein users can pick their conversion class and unit sorts. The program uses trendy mathematical formulation for correct conversions. This easy device is useful for students, professionals, and all and sundry needing short unit conversions.
STEP 1->Prompt the person for the type of conversion:
The application begins by means of asking the person to pick out the kind of unit they want to transform: temperature, weight, or period. This uses a print statement and the input() function to capture the consumer’s choice.
print("Choose the conversion type:") print("1. Temperature") print("2. Weight") print("3. Length")
STEP 2->Handle temperature conversions:
If the consumer selects temperature conversion, the program furthermore asks if they want to convert from Celsius to Fahrenheit or vice versa. For Celsius to Fahrenheit, the formula (temp * nine/5) 32 is used. For Fahrenheit to Celsius, the method (temp – 32) * five/9 is used.
if conversion_type == 1: print("1. Celsius to Fahrenheit") print("2. Fahrenheit to Celsius") temp_choice = int(input("Enter choice (1/2): ")) temp = float(input("Enter temperature: ")) if temp_choice == 1: # Celsius to Fahrenheit conversion formula converted_temp = (temp * 9/5) + 32 print(f"{temp}°C is {converted_temp}°F") elif temp_choice == 2: # Fahrenheit to Celsius conversion formula converted_temp = (temp - 32) * 5/9 print(f"{temp}°F is {converted_temp}°C")
STEP 3->Handle weight conversions:
If the person selects weight conversion, the system then asks whether or not they need to transform from kilograms to pounds or pounds to kilograms. For kilograms to pounds, use the formula weight * 2.20462. For pounds to kilograms, use the formula weight / 2.20462.
elif conversion_type == 2: print("1. Kilograms to Pounds") print("2. Pounds to Kilograms") weight_choice = int(input("Enter choice (1/2): ")) weight = float(input("Enter weight: ")) if weight_choice == 1: # Kilograms to Pounds conversion formula converted_weight = weight * 2.20462 print(f"{weight} kg is {converted_weight} lbs") elif weight_choice == 2: # Pounds to Kilograms conversion formula converted_weight = weight / 2.20462 print(f"{weight} lbs is {converted_weight} kg")
STEP 4->Handle period conversions:
If the consumer selects length conversion, they can then choose between meters to feet or feet to meters. For meters to feet, use the formula length * 3.28084. For feet to meters, use the formula length / 3.28084.
elif conversion_type == 3: print("1. Meters to Feet") print("2. Feet to Meters") length_choice = int(input("Enter choice (1/2): ")) length = float(input("Enter length: ")) if length_choice == 1: # Meters to Feet conversion formula converted_length = length * 3.28084 print(f"{length} meters is {converted_length} feet") elif length_choice == 2: # Feet to Meters conversion formula converted_length = length / 3.28084 print(f"{length} feet is {converted_length} meters")
STEP 5->Invalid preference managing: If the consumer enters a preference that isn’t always legitimate (i.E., not 1, 2, or three), this system prints an error message.
else: print("Invalid choice!")
OUTPUT
Choose the conversion type:
1. Temperature
2. Weight
3. Length
Enter choice (1/2/3): 1
1. Celsius to Fahrenheit
2. Fahrenheit to Celsius
Enter choice (1/2): 1
Enter temperature: 25
25.0°C is 77.0°F
--------------------------------
Choose the conversion type:
1. Temperature
2. Weight
3. Length
Enter choice (1/2/3): 1
1. Celsius to Fahrenheit
2. Fahrenheit to Celsius
Enter choice (1/2): 2
Enter temperature: 98.6
98.6°F is 37.0°C
--------------------------------
Choose the conversion type:
1. Temperature
2. Weight
3. Length
Enter choice (1/2/3): 2
1. Kilograms to Pounds
2. Pounds to Kilograms
Enter choice (1/2): 1
Enter weight: 70
70.0 kg is 154.324 lbs
--------------------------------
Choose the conversion type:
1. Temperature
2. Weight
3. Length
Enter choice (1/2/3): 2
1. Kilograms to Pounds
2. Pounds to Kilograms
Enter choice (1/2): 2
Enter weight: 150
150.0 lbs is 68.0389 kg
--------------------------------
Choose the conversion type:
1. Temperature
2. Weight
3. Length
Enter choice (1/2/3): 3
1. Meters to Feet
2. Feet to Meters
Enter choice (1/2):
1 Enter length: 5
5.0 meters is 16.4042 feet
--------------------------------
Choose the conversion type:
1. Temperature
2. Weight
3. Length
Enter choice (1/2/3): 3
1. Meters to Feet
2. Feet to Meters
Enter choice (1/2): 2
Enter length: 20
20.0 feet is 6.096 meters
--------------------------------
Choose the conversion type:
1. Temperature
2. Weight
3. Length
Enter choice (1/2/3): 5
Invalid choice!