Lab Description:

This lab we will use the functions from Program 2 (the mathematical operands we created and the menu) to show how they can be interpreted as functions.

Code:

#program to add, subtract, multiply, divide, print remainder and

#compare two integer values

#Created by Daniel Perry 10/10/2013

#function definitons follow

#Multiplies 2 integers
def Multiply():
print(‘Multiplication’)
x=int(input(‘What is the first number?\n’))
y=int(input(‘What is the second number?\n’))
print(x*y)
print(‘\n’)
#Divides 2 integers
def Division():
print(‘Division’)
x=int(input(‘What is the first number?\n’))
y=int(input(‘What is the second number?\n’))
print(x/y)
print(‘\n’)

#Adds 2 integers
def Addition():
print(‘Addition’)
x=int(input(‘What is the first number?\n’))
y=int(input(‘What is the second number?\n’))
print(x+y)
print(‘\n’)

#Subtracts 2 integers
def Subtraction():
print(‘Subtraction’)
x=int(input(‘What is the first number?\n’))
y=int(input(‘What is the second number?\n’))
print(x-y)
print(‘\n’)

#Compares 2 integers
def Comparision():
print(‘Comparison’)
x=int(input(‘What is the first number?\n’))
y=int(input(‘What is the second number?\n’))
if x<y:
print(x, ‘is less than’, y)
elif x>y:
print(x, ‘is greater than’, y)
elif x==y:
print(x, ‘is equal to’, y)

#Prints the remainder of 2 functions
def Remainder():
print(‘Remainder after Division’)
x=int(input(‘What is the first number?\n’))
y=int(input(‘What is the second number?\n’))
print(x, ‘Divided by’, y, ‘equals’, x/y, ‘Remainder’, x%y)

#Exits the program
#test of Goodbye function, not working right now
def Goodbye():
print(‘Goodbye’)
loop_controller=7
return loop_controller
#Displays the Menu
def Menu():
loop_controller=0
while loop_controller!=7:
print(‘1. Multiply’)
print(‘2. Division’)
print(‘3. Addition’)
print(‘4. Subtraction’)
print(‘5. Comparison’)
print(‘6. Remainder’)
print(‘7. Exit\n’)
loop_controller = input(‘What Function do you want to do?\n’)
if loop_controller==’1′:
Multiply()
elif loop_controller==’2′:
Division()
elif loop_controller==’3′:
Addition()
elif loop_controller==’4′:
Subtraction()
elif loop_controller==’5′:
Comparision()
elif loop_controller==’6′:
Remainder()
elif loop_controller==’7′:
loop_controller=Goodbye()

#end of function definitions
#START OF PROGRAM
Menu()

 

 

Screenshots:

Screenshot of output and source code for Lab # 3

 

emt 1111 Daniel Perry lab 3 revised output