0% found this document useful (0 votes)
2 views2 pages

Untitled Document (20)

The document contains a Python program that provides a temperature conversion calculator. It includes functions to convert between Celsius, Fahrenheit, and Kelvin, and a menu-driven interface for user interaction. Users can select the type of conversion they want to perform and input the temperature to receive the converted value.

Uploaded by

mistermasterchin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Untitled Document (20)

The document contains a Python program that provides a temperature conversion calculator. It includes functions to convert between Celsius, Fahrenheit, and Kelvin, and a menu-driven interface for user interaction. Users can select the type of conversion they want to perform and input the temperature to receive the converted value.

Uploaded by

mistermasterchin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

def celsius_to_fahrenheit(celsius):

return (celsius * 9/5) + 32

def fahrenheit_to_celsius(fahrenheit):
return (fahrenheit - 32) * 5/9

def celsius_to_kelvin(celsius):
return celsius + 273.15

def kelvin_to_celsius(kelvin):
return kelvin - 273.15

def fahrenheit_to_kelvin(fahrenheit):
return celsius_to_kelvin(fahrenheit_to_celsius(fahrenheit))

def kelvin_to_fahrenheit(kelvin):
return celsius_to_fahrenheit(kelvin_to_celsius(kelvin))

def menu():
print("Welcome to the temperature calculator!")
print("Press 1 for celsius to fahrenheit")
print("Press 2 for fahrenheit to celsius")
print("Press 3 for celsius to kelvin")
print("Press 4 for kelvin to celsius")
print("Press 5 for fahrenheit to kelvin")
print("Press 6 for kelvin to fahrenheit")
print("Press 7 to exit")

def main_menu(choice=None):
while True:
if choice is None:
menu()
choice = int(input("Enter a number between 1 and 7: "))

if choice not in [1,2,3,4,5,6,7]:


print("Invalid choice")
elif choice == 7:
print("Calculator is closing")
break

temperature = float(input("Please enter a temperature: "))

if choice == 1:
result = celsius_to_fahrenheit(temperature)
print(str(temperature) + " °C is equal to " + str(round(result, 2)) + " °F")
elif choice == 2:
result = fahrenheit_to_celsius(temperature)
print(str(temperature) + " °F is equal to " + str(round(result, 2)) + " °C")
elif choice == 3:
result = celsius_to_kelvin(temperature)
print(str(temperature) + " °C is equal to " + str(round(result, 2)) + " K")
elif choice == 4:
result = kelvin_to_celsius(temperature)
print(str(temperature) + " K is equal to " + str(round(result, 2)) + " °C")
elif choice == 5:
result = fahrenheit_to_kelvin(temperature)
print(str(temperature) + " °F is equal to " + str(round(result, 2)) + " K")
elif choice == 6:
result = kelvin_to_fahrenheit(temperature)
print(str(temperature) + " K is equal to " + str(round(result, 2)) + " °F")

choice = None

main_menu()

You might also like