Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def get_float(prompt):
- print(prompt)
- while True:
- try:
- return float(input("> "))
- except ValueError:
- print("Please enter a number")
- done = False
- while not done:
- while True:
- print("Would you like to convert from C TO F, or F TO C?")
- convert = input("> ").lower()
- if convert in ("c to f", "f to c"):
- break
- print("Please enter a valid command.")
- while True:
- if convert == "c to f":
- val = get_float("What temperature would you like to convert to Fahrenheit?")
- print("That's %.1f degrees Fahrenheit.\n" % (val * 9 / 5 + 32))
- else:
- val = get_float("What temperature would you like to convert to Celsius?")
- print("That's %.1f degrees Celsius.\n" % ((val - 32) * 5 / 9))
- print("Is that all? (Y/N)")
- if input("> ").lower() == "y":
- print("Goodbye")
- done = True
- break
- else:
- print("")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement