Lab 3

Lab Description:

In this lab, I was told to re-write lab 2 using functions this time. i found some of the information in order to do this in class and I applied that information to do this lab. Even with the information, I had a bit of problem but with some help, I manage to do the lab.

Source Code:

def Sum(x,y):
print(x+y,’is the sum of the two integers’)
def Subtract(x,y):
print(x-y,’is the difference of the two integers’)
def Multiply(x,y):
print(x*y,’is the product of the two integers’)
def Divide(x,y):
print(x/y,’is the quotient of the two integers’)
def Remainder(x,y):
print(x%y,’is the remainder of the two numbers’)
def Compare(x,y):
if x>y:
print(‘%d is larger than %d’%(x,y))
elif x==y:
print(‘%d is equal to %d’%(x,y))
else:
print(‘%d is less than %d’%(x,y))
def menu():
print(‘The menu’)
print(‘1-Sum numbers’)
print(‘2-Subtract numbers’)
print(‘3-Multiply numbers’)
print(‘4-Divide numbers’)
print(‘5-Remainder of numbers’)
print(‘6-Compare numbers’)
print(‘7-Exit’)
choice= ”
while choice != ‘7’:
choice=input(‘The list of numbers above shows the action that will be perform next to it. Please enter a number from 1 to 7’)
print (choice)
if choice== ‘1’:
x = input(‘What is the first integer \n’)
y = input(‘What is the second integer \n’)
x= int(x)
y= int(y)
Sum(x,y)
elif choice==’2′:
x = input(‘What is the first integer \n’)
y = input(‘What is the second integer \n’)
x= int(x)
y= int(y)
Subtract(x,y)
elif choice==’3′:
x = input(‘What is the first integer \n’)
y = input(‘What is the second integer \n’)
x= int(x)
y= int(y)
Multiply(x,y)
elif choice==’4′:
x = input(‘What is the first integer \n’)
y = input(‘What is the second integer \n’)
x= int(x)
y= int(y)
Divide(x,y)
elif choice==’5′:
x = input(‘What is the first integer \n’)
y = input(‘What is the second integer \n’)
x= int(x)
y= int(y)
Remainder(x,y)
elif choice==’6′:
x = input(‘What is the first integer \n’)
y = input(‘What is the second integer \n’)
x= int(x)
y= int(y)
Compare(x,y)
elif choice==’7′:
print(‘Good Bye’)
else:
print (‘Please choose a number from 1 to 7’)

menu()

Screenshot:Lab3emt1111

 

 

Leave a Reply

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