Demo entry 6344812

Temp Convertor

   

Submitted by anonymous on Jan 24, 2017 at 13:20
Language: Python 3. Code size: 1.4 kB.

# My Temperature convertor program
# By Gemma Charters

def print_options():
    # prints out a menu for the user to choose from
    print("****Please choose one of the following*******")
    print(" p - print options")
    print(" c - convert FROM celsius")
    print(" f - convert FROM fahrenheit")
    print(" q - quit the program")

def celsius_to_fahrenheit(c_temp):
    # takes the celsius temperatur and converts to fahrenheit
    return 9.0 / 5.0 * c_temp + 32

def fahrenheit_to_celsius(f_temp):
    # takes the fahrenheit temperature and converts to celsius
    return (f_temp - 32.0) * 5.0 / 9.0

print_options()
choice = input("Option: ")
while choice != "q":
    # loops until the user decides to quit the program

    if choice == "c":
        # celsius conversion
        c_temp = float(input("Celsius temperature: "))
        print("The fahrenheit temperature is", celsius_to_fahrenheit(c_temp))
        
    elif choice == "f":
        # fahrenheit conversion
        f_temp = float(input("Fahrenheit temperature: "))
        print("The celsius temperature is", fahrenheit_to_celsius(f_temp))
        
    elif choice == "p":
        # reprint menu
        print_options()
    else:
        
        # error in input
        print("an invalid choice has been entered, please try again")
        
    choice = input("New option: ")

print("goodbye")

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).