Lab Description:
This lab is about the use of for, while and other definitive statements in order to make a program that prompts the user for an input and performs the math operands on it learned in our previous lab.
Code:
Code for Exercise (does not have the right indentation to run directly from cut and paste, please use the .py file):
This program was written in Python 3.3 and performs multiple operations on two integers provided from a user. It was created by Daniel Perry on 10/6/2013.
#program to add, subtract, multiply, divide, print remainder and
#compare two integer values
function=0
while function!=7:
print(‘1. Multiply’)
print(‘2. Division’)
print(‘3. Addition’)
print(‘4. Subtraction’)
print(‘5. Comparison’)
print(‘6. Remainder’)
print(‘7. Exit\n’)
function= input(‘What Function do you want to do?\n’)
if function==’1′:
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’)
elif function==’2′:
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’)
elif function==’3′:
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’)
elif function==’4′:
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’)
elif function==’5′:
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)
print(‘is less than’)
print(y)
elif x>y:
print(x)
print(‘is greater than’)
print (y)
elif x==y:
print(x)
print(‘is equal to’)
print(y)
elif function==’6′:
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)
elif function==’7′:
function=7
Screenshots:
No comments