arikSarkar

TemperatureConv

Sep 23rd, 2017
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.75 KB | None | 0 0
  1. # Temperature Conversion Program
  2.  
  3. def menu():
  4.     print("\n1. Celsius to Fahrenheit")
  5.     print("2. Fahrenheit to Celsius")
  6.     print("3. Exit")
  7.     choice = int(input("Enter a choice: "))
  8.     return choice
  9.  
  10. def toCelsius(f):
  11.     return int((f - 32) / 1.8)
  12.  
  13. def toFahrenheit(c):
  14.     return int(c * 1.8 + 32)
  15.    
  16. def main():
  17.     choice = menu()
  18.     while choice != 3:
  19.         if choice == 1:
  20.         c = eval(input("Enter degrees Celsius: "))
  21.             print(str(c) + "C = " + str(toFahrenheit(c)) + "F")
  22.         elif choice == 2:
  23.             f = eval(input("Enter degrees Fahrenheit: "))
  24.             print(str(f) + "F = " + str(toCelsius(f)) + "C")
  25.         else:
  26.             print("Invalid choice.")
  27.         choice = menu()
  28.    
  29. main()
Add Comment
Please, Sign In to add comment