LAB 3

Lab Description:

The Purpose of this lab was to create a menu that is linked to list of expressions that when selected executes the expressions chosen. Like Lab 2 this Lab starts off by assigning number of options to expressions to be executed.The difference is that these expressions,being locally in a while statement, are conditionally chained.

Code:

 

option = 1 
option = 2
option = 3
option = 4
option = 5
option = 6
option = 7
print ("1-The sum x + y")
print ("2-The difference x – y")
print ("3-The product x * y")
print ("4-The quotient x/y")
print ("5-The remainder x%y")
print ("6-Whether x is less than, equal, or greater than y")
print ("7-Exit")
option = input ("Enter option # from menu to perform operation or Enter number (7) to Exit")
while option <7 :
          
           
        if option == 1:
                   X = input ("Enter X ")
                   Y = input ("Enter Y ")
                   Z = X + Y
                   print "X + Y = ", Z
                   print option 
                   (option == 2 );
                   option = input ("Enter option # from menu to perform operation or Enter nember (7) to Exit")
                  #Print option

        elif option == 2:
                   X = input ("Enter X ")
                   Y = input ("Enter Y ")
                   Z = X - Y
                   print "X - Y = ", Z
                   option = 3
                   print option 
                   (option == 3) ;
                   option = input ("Enter option # from menu to perform operation or Enter number(7) to Exit ")
                  #Print option

        elif (option == 3):
                   X = input ("Enter X ")
                   Y = input ("Enter Y ")
                   Z = X * Y
                   print "X * Y = ", Z
                   option = 4
                   print option 
                   (option == 4) ;
                   option = input ("Enter option # from menu to perform operation or Enter number (7) to Exit ")
                  #Print option

        elif (option == 4):
                   X = input ("Enter X ")
                   Y = input ("Enter Y ")
                   Z= X / Y
                   print "X / Y =  ", Z
                   option = 5
                   print option 
                   (option == 5) ;
                   option = input ("Enter option # from menu to perform operation or Enter number (7) to Exit ")
                  #Print option

        elif (option  == 5):
                   X = input ("Enter X ")
                   Y = input ("Enter Y ")
                   Z = X % Y
                   print "X % Y = Z ", Z
                   option = 6
                   print option 
                   (option == 6) ;              
                   option = input  ("Enter option # from menu to perform operation menue or Enter number (7) to Exit ")
                  #Print option

        elif  (option == 6) :
                   X = input ("Enter X ")
                   Y = input ("Enter Y ")
                   if  X  Y :
                        print 'X is greater than Y'
                   else :
                         print 'X and Y are equal'
                   option = input ("Enter option # from menu to perform operation or Enter number (7) to Exit")     
        if    (option == 7)  :        
               print ("goodbye")

 

Screenshots:

Lab3screencapture

Leave a Reply

Your email address will not be published. Required fields are marked *