def celsius_to_farenheit(t):
= t*(9/5)+32
t_fahrenheit return t_fahrenheit
= 30
answer = float(answer)
t_celsuis = celsius_to_farenheit(t_celsuis)
t print("Farenheit:", t)
Farenheit: 86.0
def celsius_to_farenheit(t):
t_fahrenheit = t*(9/5)+32
return t_fahrenheit
answer = 30
t_celsuis = float(answer)
t = celsius_to_farenheit(t_celsuis)
print("Farenheit:", t)
Farenheit: 86.0
def show_user_menu(): # Menu function
print('\nMenu Options:') # Using \n for new line separator
print('\n1. Fahrenheit to Celsius')
print('2. Celsius to Fahrenheit')
print('3. Fahrenheit to Kelvin')
print('4. Kelvin to Fahrenheit')
print('5. Celsius to Kelvin')
print('6. Kelvin to Celsius')
print('\nType "q" to End Program')
def f_to_c(): # Fahrenheit to Celsius function
answer = input('Enter a temperature in Fahrenheit: ')
t_fahrenheit = float(answer)
t = float((t_fahrenheit - 32) * 5/9)
print("\nCelsius: ",t)
def c_to_f(): # Celsius to Fahrenheit function
answer = input('Enter a temperature in Celsius: ')
t_celsius = float(answer)
t = float((t_celsius * 9/5) + 32)
print("\nFahrenheit: ",t)
def f_to_k(): # Fahrenheit to Kelvin function
answer = input('Enter a temperature in Fahrenheit: ')
t_fahrenheit = float(answer)
t = float(t_fahrenheit-32) * 5/9 + 273.15
print("\nKelvin: ",t)
def k_to_f(): # Kelvin to Fahrenheit function
answer = input('Enter a temperature in Kelvin: ')
t_kelvin = float(answer)
t = (t_kelvin - 273.15) * 9/5 + 32
print("\nFahrenheit: ",t)
def c_to_k(): # Celsius to Kelvin function
answer = input('Enter a temperature in Celsius: ')
t_celsius = float(answer)
t = t_celsius + 273.15
print("\nKelvin: ",t)
def k_to_c(): # Kelvin to Celsius function
answer = input('Enter a temperature in Kelvin: ')
t_kelvin = float(answer)
t = t_kelvin - 273.15
print("\nCelsius: ", t)
def undefined(): # Invalid option function
print("\nThat is not a valid option...")
print ("\nPlease try again!")
loop = True # Loop program after invalid option or conversion functions
while loop:
show_user_menu()
option = input('Select an option from the menu above: ')
if option not in ('1', '2', '3', '4', '5', '6', 'q'):
undefined()
if option == '1':
f_to_c()
if option == '2':
c_to_f()
if option == '3':
f_to_k()
if option == '4':
k_to_f()
if option == '5':
c_to_k()
if option == '6':
k_to_c()
if option == 'q': # End program loop if q is selected
print ("\nProgram Ended")
loop = False
Menu Options:
1. Fahrenheit to Celsius
2. Celsius to Fahrenheit
3. Fahrenheit to Kelvin
4. Kelvin to Fahrenheit
5. Celsius to Kelvin
6. Kelvin to Celsius
Type "q" to End Program
That is not a valid option...
Please try again!
Menu Options:
1. Fahrenheit to Celsius
2. Celsius to Fahrenheit
3. Fahrenheit to Kelvin
4. Kelvin to Fahrenheit
5. Celsius to Kelvin
6. Kelvin to Celsius
Type "q" to End Program
Celsius: 10.0
Menu Options:
1. Fahrenheit to Celsius
2. Celsius to Fahrenheit
3. Fahrenheit to Kelvin
4. Kelvin to Fahrenheit
5. Celsius to Kelvin
6. Kelvin to Celsius
Type "q" to End Program
Kelvin: 260.92777777777775
Menu Options:
1. Fahrenheit to Celsius
2. Celsius to Fahrenheit
3. Fahrenheit to Kelvin
4. Kelvin to Fahrenheit
5. Celsius to Kelvin
6. Kelvin to Celsius
Type "q" to End Program
Program Ended
def ask_for_conversion():
conversion_type = input("What conversion do you want to do? 1. Celsius --> Farenheit or 2. Farenheit --> Celsius")
if conversion_type=="1":
def fahrenheit_to_celsius(t):
t_celsius = (t-32)*(5/9)
return t_celsius
answer = input('Enter a temperature in Fahrenheit: ')
t_fahrenheit = float(answer)
t = fahrenheit_to_celsius(t_fahrenheit)
print("Celsius: ", t)
elif conversion_type=="2":
answer = input('Enter a temperature in Celsius: ')
t_celsuis = float(answer)
t = celsius_to_farenheit(t_celsuis)
print("Farenheit:", t)
else:
print("Select a valid conversion type, 1 or 2")
ask_for_conversion()
Farenheit: 50.0
quit = False
while quit == False:
ask_for_conversion()
another_conversion = input("Press 'q' to quit, or any other key to do another conversion")
if another_conversion=="q":
break
else:
"Let's do another conversion!"
Celsius: 10.0
Celsius: 10.0
Celsius: 37.77777777777778
# T(°C) = T(K) - 273.15
def celsius_to_kelvin(t):
t_celsuis=t-273.15
return t_celsuis
def kelvin_to_celsius(t):
t_kelvin=t+273.15
return t_kelvin
# Converting Farenheit --> Celsius --> Kelvin
def farenheit_to_kelvin(t):
t_celsuis=fahrenheit_to_celsius(t)
t_kelvin=t_celsuis-273.15
return t_kelvin
# Converting Kelvin --> Celsius --> Farenheit
def kelvin_to_farenheit(t):
t_celsuis=t+273.15
t_fahrenheit = celsius_to_farenheit(t_celsuis)
return t_fahrenheit
while True:
conversion_type=input("What you do want to convert: 1. Celsius to Kelvin, 2. Kelvin to Celsius, 3. Farenheit to Kelvin or 4. Kelvin to Farenheit")
if conversion_type=="1":
answer = input('Enter a temperature in Celsius: ')
t_fahrenheit = float(answer)
t = celsius_to_kelvin(t_fahrenheit)
print("Kelvin: ", t)
elif conversion_type=="2":
answer = input('Enter a temperature in Kelvin: ')
t_fahrenheit = float(answer)
t = kelvin_to_celsius(t_fahrenheit)
print("Celsius: ", t)
elif conversion_type=="3":
answer = input('Enter a temperature in Farenheit: ')
t_fahrenheit = float(answer)
t = farenheit_to_kelvin(t_fahrenheit)
print("Celsius: ", t)
elif conversion_type=="4":
answer = input('Enter a temperature in Kelvin: ')
t_fahrenheit = float(answer)
t = kelvin_to_farenheit(t_fahrenheit)
print("Farenheit: ", t)
else:
print("Enter a valid number: 1, 2, 3 or 4")
another_conversion = input("Press 'q' to quit, or any other key to do another conversion")
if another_conversion=="q":
break
Kelvin: -263.15