Lab 3

Lab 3

Description

In this lab we learned how to use functions.

Code

# Alex Albert
# Lab 3 Functions
# Section: 9306
# Date: 3/07/2013

def xy1(x,y):
return x+y
def xy2(x,y):
return x-y
def xy3(x,y):
return x * y
def xy4(x,y):
return x/y
def xy5(x,y):
return x%y
def xy6(x,y):
return x < y
def xy7(x,y):
return Exit
print(‘———————————-‘)
x = input (‘Enter a value for x:’)
y = input (‘Enter a value for y:’)
while x!=0 and y!=0:
print (‘—————————‘)
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’
print(‘———————————-‘)
selection = input (‘ Please enter a selection ‘)
if selection ==1:
print (‘The sum of ‘,x,’ + ‘,y, ‘=’), xy1(x,y)
elif selection ==2:
print (‘The difference of ‘,x,’ – ‘,y,’=’), xy2(x,y)
elif selection ==3:
print (‘The product of ‘,x,’ * ‘,y, ‘=’), xy3(x,y)
elif selection ==4:
print (‘The quotient of ‘,x,’ /’ ,y, ‘=’), xy4(x,y)
elif selection ==5:
print (‘The remainder of ‘,x, ‘ + ‘,y, ‘=’), xy5(x,y)
elif selection ==6:
if x < y:
print ‘ The number: ‘, x,’ is less than’ ,y,
elif x > y:
print ‘ The number: ‘, x,’ is greater than’ ,y,
else:
print ‘ The number: ‘, x,’ is equal to’ ,y,
elif selection ==7:
print (‘End program.’), xy7(x,y)
print (‘——————————-‘)
x = input (‘Enter a value for x:’)
y = input (‘Enter a value for y:’)

Screenshot