Lab 3
Lab3
Description:
This is lab #3
Functions
Code:
def addition (x,y): z=x+y return z def subtract(x,y): z=x-y return z def multiplication(x,y): z=x*y return z def divide(x,y): z=x/y return z def remainder(x,y): z=x%y return z
def xgy(x,y): if x==y: return (‘x equals y’) elif x<y: return (‘x less than y’) else: return (‘x greater than y’) def print_menu(): print (‘1.addition’) print (‘2.subtraction’) print (‘3.multiplication’) print (‘4.divide’) print (‘5.remainder’) print (‘6.xgy’) print (‘choose menu item by type in a number’)
print_menu() menu_item = input (‘menu_item?’) while (menu_item !=0): x = int (input (‘Enter first number: ‘)) y = int (input (‘Enter second number: ‘)) print (x)
if (menu_item==1): plus=addition(x,y) print (plus) if (menu_item==2): sub=subtract(x,y) print (sub) if (menu_item==3): mul=multiplication(x,y) print (mul) if (menu_item==4): div=divide(x,y) print (div) if (menu_item==5): rem=remainder(x,y) print (rem) if (menu_item==6): compare=xgy(x,y) print (compare)
print_menu() menu_item = input (‘menu_item?’)
screenshot: