Lab 3

Lab Description:

In this lab, I had to use the code for the lab two and essentially rewrite the code and add functions. Rewriting requires that the code now gives the user a menu to choose what they want to perform the operation. The user enters one of the numbers that are shown in the menu, then enters two values​​, the program calls a function, and the operation is performed, they have chosen. Then they are able to continue to do operations with new inputs each time. If the user selects option 7, the program exits.

 

Code:

print'Main Menu:  '
print'1 - Sum numbers'
print'2 - Subtract numbers'
print'3 - Multiply numbers'
print'4 - Divide numbers'
print'5 - Remainder numbers'
print'6 - Compare numbers'
print'7 - Exit'
print''
def A(x,y): print 'x+y =',(x+y)
def B(x,y): print 'x-y =',(x-y)
def C(x,y): print 'x*y =',(x*y)
def D(x,y): print 'x/y =',(x/y)
def E(x,y): print 'x%y =',(x%y)
def F(x,y):
    if x>y: print('%d>%d'%(x,y))
    elif x<y: print('%d<%d'%(x,y))
    else: print ('%d=%d'%(x,y)) 
z=input('Please Enter Selection: ')
v=int(z)
while (v != 7):
    x=input ('Enter x:')
    y=input ('Enter y:')
    x=int(x)
    y=int(y)
    print''
    if   z==1:A(x,y)
    elif z==2:B(x,y)
    elif z==3:C(x,y)
    elif z==4:D(x,y)
    elif z==5:E(x,y)
    elif z==6:F(x,y)
    print''
    print'Main Menu:  '
    print'1 - Sum numbers'
    print'2 - Subtract numbers'
    print'3 - Multiply numbers'
    print'4 - Divide numbers'
    print'5 - Remainder numbers'
    print'6 - Compare numbers'
    print'7 - Exit'
    print''
    z=input('Please Enter Selection: ')
    v=int(z)

 

lab3

 

Screenshots:

 

lab3a

lab3b

lab3c

Leave a Reply

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