Advertisement
eXFq7GJ1cC

Untitled

Aug 30th, 2012
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.03 KB | None | 0 0
  1. def get_float(prompt):
  2.     print(prompt)
  3.     while True:
  4.         try:
  5.             return float(input("> "))
  6.         except ValueError:
  7.             print("Please enter a number")
  8.  
  9. done = False
  10.  
  11. while not done:
  12.  
  13.     while True:
  14.         print("Would you like to convert from C TO F, or F TO C?")
  15.         convert = input("> ").lower()
  16.         if convert in ("c to f", "f to c"):
  17.             break
  18.         print("Please enter a valid command.")
  19.            
  20.     while True:
  21.         if convert == "c to f":
  22.             val = get_float("What temperature would you like to convert to Fahrenheit?")
  23.             print("That's %.1f degrees Fahrenheit.\n" % (val * 9 / 5 + 32))
  24.         else:
  25.             val = get_float("What temperature would you like to convert to Celsius?")
  26.             print("That's %.1f degrees Celsius.\n" % ((val - 32) * 5 / 9))
  27.  
  28.         print("Is that all? (Y/N)")
  29.         if input("> ").lower() == "y":
  30.             print("Goodbye")
  31.             done = True
  32.             break
  33.         else:
  34.             print("")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement