2.4 ממיר פתרון
print("Welcome to the converter!")
while True:
print("Choose the type of conversion you would like to perform:")
print("1: Temperature (Fahrenheit to Celsius and vice versa)")
print("2: Length (Inches to Centimeters and vice versa)")
print("3: Weight (Pounds to Kilograms and vice versa)")
print("4: Distance (Miles to Kilometers and vice versa)")
print("5: Volume (Gallons to Liters and vice versa)")
choice = input("Enter the number corresponding to your choice: ")
if choice == '1':
temp_choice = input("Type 'F' to convert Fahrenheit to Celsius or 'C' to convert Celsius to Fahrenheit: ").upper()
if temp_choice == 'F':
fahrenheit = float(input("Enter temperature in Fahrenheit: "))
celsius = (fahrenheit - 32) * 5 / 9
print(f"{fahrenheit} Fahrenheit is {celsius} Celsius")
elif temp_choice == 'C':
celsius = float(input("Enter temperature in Celsius: "))
fahrenheit = (celsius * 9 / 5) + 32
print(f"{celsius} Celsius is {fahrenheit} Fahrenheit")
else:
print("Invalid choice.")
elif choice == '2':
length_choice = input("Type 'I' to convert Inches to Centimeters or 'C' to convert Centimeters to Inches: ").upper()
if length_choice == 'I':
inches = float(input("Enter length in Inches: "))
centimeters = inches * 2.54
print(f"{inches} Inches is {centimeters} Centimeters")
elif length_choice == 'C':
centimeters = float(input("Enter length in Centimeters: "))
inches = centimeters / 2.54
print(f"{centimeters} Centimeters is {inches} Inches")
else:
print("Invalid choice.")
elif choice == '3':
weight_choice = input("Type 'P' to convert Pounds to Kilograms or 'K' to convert Kilograms to Pounds: ").upper()
if weight_choice == 'P':
pounds = float(input("Enter weight in Pounds: "))
kilograms = pounds * 0.453592
print(f"{pounds} Pounds is {kilograms} Kilograms")
elif weight_choice == 'K':
kilograms = float(input("Enter weight in Kilograms: "))
pounds = kilograms / 0.453592
print(f"{kilograms} Kilograms is {pounds} Pounds")
else:
print("Invalid choice.")
elif choice == '4':
distance_choice = input("Type 'M' to convert Miles to Kilometers or 'K' to convert Kilometers to Miles: ").upper()
if distance_choice == 'M':
miles = float(input("Enter distance in Miles: "))
kilometers = miles * 1.60934
print(f"{miles} Miles is {kilometers} Kilometers")
elif distance_choice == 'K':
kilometers = float(input("Enter distance in Kilometers: "))
miles = kilometers / 1.60934
print(f"{kilometers} Kilometers is {miles} Miles")
else:
print("Invalid choice.")
elif choice == '5':
volume_choice = input("Type 'G' to convert Gallons to Liters or 'L' to convert Liters to Gallons: ").upper()
if volume_choice == 'G':
gallons = float(input("Enter volume in Gallons: "))
liters = gallons * 3.78541
print(f"{gallons} Gallons is {liters} Liters")
elif volume_choice == 'L':
liters = float(input("Enter volume in Liters: "))
gallons = liters / 3.78541
print(f"{liters} Liters is {gallons} Gallons")
else:
print("Invalid choice.")
else:
print("Invalid choice. Please select a valid conversion type.")