In [2]:
#importing the clear_output command from Ipython.diplay library 
from IPython.display import clear_output
#installs the sleep() command from the sleep library
from time import sleep

#defines the function that asks if you want to leave
def leave():
        #asks if you want to try again
        exitquestion = input("would you like to convert another tempurature? y or n ==> ")
        #determines if the answer was y or Y and if so it runs its own function
        if exitquestion == "y" or exitquestion == "Y":
            #clears outputs
            clear_output()
            #you back to main function
            main()
        #determines if response was n or N if so then runs own function
        elif exitquestion == "n" or exitquestion == "N":
            #clears all outputs
            clear_output()
            #tells you to have a good day
            print("have a good day")
        #if none of the other options happen then this command happens
        else:
            #clears all outputs
            clear_output()
            #runs leave function again
            leave()

#defines the function that converts celsius to farenheit
def farenheit():
    #checks for errors
    try:
        #clears all outputs
        clear_output()
        #asks question that gives us our tempurature that is in celsius
        temp = float(input("Enter your tempurature ==> "))
        #converts the tempurature to farenheit
        actualtemp = (temp * 9/5) + 32
        #variable for response
        response = "Your tempurature of {} degrees celsius has been convertered to {} degrees farenheit"
        #prints response with proper formating
        print(response.format(temp, actualtemp))
        #runs the leave function
        leave()
    #if errors appear this function is run
    except:
        #tells you to only insert numbers
        print("only numbers please")
        #waits three seconds
        sleep(3)
        #runs the farenheit function
        farenheit()
        
#defines the function that converts farenheit to celsius
def celsius():
    #checks for errors
    try:
        #clears all outputs
        clear_output()
        #asks for tempurature that we are converting to celsius 
        temp = float(input("enter your tempurature ==> "))
        #converts the tempurature to celsius
        actualtemp = (temp - 32) * 5/9
        #variable thats used for response
        response = "Your tempurature of {} degrees farenheit has been convertered to {} degrees celsius"
        #prints the response in a formated text
        print(response.format(temp, actualtemp))
        #runs leave function
        leave()
    #if code has error this function is run
    except:
        #tells you to insert numbers only
        print("Only numbers please")
        #waits three seconds
        sleep(3)
        #runs celsius function
        celsius()

#defines the main function
def main():
    #tells you the key to press to convert celsius to farenheit
    print("To convert from celsius to farenheit press f")
    #tells you the key to prss to convert farenheit to celsius
    print("To convert from farenheit to celsius press c")
    #ask you to enter one of two keys to give the variable a value
    converter = str(input("c or f ==> "))
    #tells us if the user pressed f then to run its function
    if converter == "f" or converter == "F":
        #runs the farenheit command
        farenheit()
    #tell us if the user pressed c then to run its function
    elif converter == "c" or converter == "C":
        #runs the celsius function
        celsius()
    #tells us if the other two options didn't happen then the program runs this command
    else:
        #tells user to only use c or f 
        print("enter a c or f please")
        #clears the outputs
        clear_outputs()
        #runs the main function
        main()
        
#tells us this is the end of the main function      
main()
have a good day
In [ ]: