Lab 3

Lab Description:

I initially defined the print menu. Then I continued to define the operations the program would use later on when the user made their selection concerning which operation to compute the variables. Then the program printed the menu. Then program asked the user to enter their choice. Then program asked for the x and y inputs. And while the selection did not equal to 7, the menu would reprint and program would continue to run until user decided to enter 7 as their choice to exit the program.

Source Code:

def menu():

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’)

 

def add(x,y):

result = int(x) + int(y)

return x + y

print (add(x,y))

def sub(x,y):

result = int(x)-int(y)

return x – y

print (sub(x,y))

def mul(x,y):

result = int(x)-int(y)

return x * y

print (mul(x,y))

def div(x,y):

result = int(x) / int(y)

return x/y

print (div(x,y))

def remainder(x,y):

result = int(x) % int(y)

return x%y

print (remainder (x,y))

def compare(x,y):

result =(‘Whether x is less than, equal, or greater than y:’), x<y, x==y, x>y,

return result

print (compare(x,y))

 

print menu()

 

selection = input(‘Please enter your choice:’)

x=input(‘Enter your x value:’)

y=input(‘Enter your y value:’)

while selection !=7:

if selection == 1:

print (add(x,y))

elif selection == 2:

print (sub(x,y))

elif selection == 3:

print (mul(x,y))

elif selection == 4:

print (div(x,y))

elif selection == 5:

print (remainder (x,y))

elif selection == 6:

print (compare(x,y))

else:

print menu()

selection = input(‘Please enter your choice:’)

x=input(‘Enter your x value:’)

y=input(‘Enter your y value:’)