Lab Description:

In this lab, I was instructed to make a program that displays the options ” (1) enter a number (2) exit. If option (1) was pressed, the program should ask the user to input two numbers, (x and y) and proceed to calculate and display basic math functions as well as display whether the first number (x) is greater than (y). Afterwards, the menu should be displayed again and ” proceed accordingly until the user decides to exit”. I was able to make the program as well as add a personal touch. When the user exits the program, the program displays “Thank you for using Delacruz Calculator” .

Code:

Numerical = True # random variable to use for while loop
while Numerical != False :
    option = input ("Menu (1) Enter Numbers (2) Exit")
    #print "option selected" , option
    if (option==1) :
        x =input ( "Enter x: ")
        y =input ( "Enter y: ")
        #print "Value of x", x
        #print "value of y", y
        z = x + y
        print " x + y = ", z
        z = x - y
        print " x - y = ", z
        z = x * y
        print " x * y = ", z
        z = x / y
        print " x / y = ", z
        z = x % y
        print " x & y = ", z
        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 (option==2) :
            print "Thank you for using Delacruz Calculator"
            # message displayed when program is closed
            break
    else :
        pass # if numerical value other than (1) or (2) is- 
             # entered in menu options, repeat menu options

Screenshots:

luis

Leave a Reply