Lab Description:

This lab is similar to the previous lab (lab 2). The only difference is that what is being asked of me in this lab is to give the user the option to choose which type of math function they would like instead of giving the user the solution to every math function all at once. This was simple to do.

Code:

option = True
while option != False :
    nam = input("Menu (1) Sum numbers (2) Subtract numbers (3) Multiply Numbers (4) Divide numbers (5) Remainder of numbers (6) compare numbers (7) exit")
    #print "option selected" , option
    if (nam==1) :
        x = input("Input first number(x)")
        y = input("Input second number(y)")
        #Print value of X
        #Print value of Y
        try : #Perform operation using function
            def Math_baby(poops) :
                print "x + y = ", poops
            Math_baby(x + y)
        except : # if function fails to perform properly, perform operation by assigning operation to z and print
            z = x + y
            print "x + y = ",z
    if (nam==2) :
        x = input("Input first number(x)")
        y = input("Input second number(y)")
        try :
            def Math_toddler(pees) :
                print "x - y = ", pees
            Math_toddler(x - y)
        except :
            z = x - y
            print "x - y = ",z
    if (nam==3) :
        x = input("Input first number(x)")
        y = input("Input second number(y)")
        try :
            def Math_preteen(whines) :
                print "x * y = ",whines
            Math_preteen(whines)
        except:
            z = x * y
            print " x * y = ",z
    if (nam==4) :
        x = input("Input first number(x)")
        y = input("Input second number(y)")
        try :
            def Math_teen(grows) :
                print "x / y = ", grows
            Math_teen(x / y)
        except:
            z = x + y
            print "x + y",z
    if (nam==5) :
        x = input("Input first number(x)")
        y = input("Input second number(y)")
        try :
            def Math_man(flys) :
                print "x % y = ", flys
            Math_man(x % y)
        except:
            z = x % y
        print " x & y = ", z
    if (nam==6) :
        x = input("Input first number(x)")
        y = input("Input second number(y)")
        if x > y :
            print " x is greater than y "
        elif x == y :
            print " x is equal to y "
        else :
            print " x is less than y "
    elif (nam==7) :
        print "Thank for using Delacruz Calculator"
        break # closes the program and displays closing message
    elif (nam==str) :
        pass
    else:
        pass # Does absolutely nothing...

Screenshots:

reolo

Leave a Reply