-
Notifications
You must be signed in to change notification settings - Fork 0
/
measurement_converter.py
37 lines (31 loc) · 1.22 KB
/
measurement_converter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
def fahrenheit_to_celsius(fahrenheit):
return (fahrenheit - 32) * 5/9
def celsius_to_fahrenheit(celsius):
return celsius * 9/5 + 32
def inches_to_centimeters(inches):
return inches * 2.54
def centimeters_to_inches(centimeters):
return centimeters / 2.54
def main():
print("Welcome to the Unit Converter!")
print("1. Fahrenheit to Celsius")
print("2. Celsius to Fahrenheit")
print("3. Inches to Centimeters")
print("4. Centimeters to Inches")
choice = input("Enter your choice (1/2/3/4): ")
if choice == '1':
f = float(input("Enter temperature in Fahrenheit: "))
print("Temperature in Celsius:", fahrenheit_to_celsius(f))
elif choice == '2':
c = float(input("Enter temperature in Celsius: "))
print("Temperature in Fahrenheit:", celsius_to_fahrenheit(c))
elif choice == '3':
inches = float(input("Enter length in inches: "))
print("Length in centimeters:", inches_to_centimeters(inches))
elif choice == '4':
cm = float(input("Enter length in centimeters: "))
print("Length in inches:", centimeters_to_inches(cm))
else:
print("Invalid choice. Please choose 1, 2, 3, or 4.")
if __name__ == "__main__":
main()