-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemperature.py
57 lines (48 loc) · 1.95 KB
/
temperature.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
def celsius_to_fahrenheit(celsius):
return (celsius * 9/5) + 32
def celsius_to_kelvin(celsius):
return celsius + 273.15
def fahrenheit_to_celsius(fahrenheit):
return (fahrenheit - 32) * 5/9
def fahrenheit_to_kelvin(fahrenheit):
celsius = fahrenheit_to_celsius(fahrenheit)
return celsius_to_kelvin(celsius)
def kelvin_to_celsius(kelvin):
return kelvin - 273.15
def kelvin_to_fahrenheit(kelvin):
celsius = kelvin_to_celsius(kelvin)
return celsius_to_fahrenheit(celsius)
while True:
print("Choose an option:")
print("1. Celsius to Fahrenheit")
print("2. Celsius to Kelvin")
print("3. Fahrenheit to Celsius")
print("4. Fahrenheit to Kelvin")
print("5. Kelvin to Celsius")
print("6. Kelvin to Fahrenheit")
print("7. Quit")
choice = input("Enter your choice (1/2/3/4/5/6/7): ")
if choice == '7':
break
if choice in ('1', '2', '3', '4', '5', '6'):
temperature = float(input("Enter temperature value: "))
if choice == '1':
result = celsius_to_fahrenheit(temperature)
print(f"{temperature}°C is equal to {result}°F")
elif choice == '2':
result = celsius_to_kelvin(temperature)
print(f"{temperature}°C is equal to {result} K")
elif choice == '3':
result = fahrenheit_to_celsius(temperature)
print(f"{temperature}°F is equal to {result}°C")
elif choice == '4':
result = fahrenheit_to_kelvin(temperature)
print(f"{temperature}°F is equal to {result} K")
elif choice == '5':
result = kelvin_to_celsius(temperature)
print(f"{temperature} K is equal to {result}°C")
elif choice == '6':
result = kelvin_to_fahrenheit(temperature)
print(f"{temperature} K is equal to {result}°F")
else:
print("Invalid input. Please choose a valid option.")