Lab 3

Code:

# Asks the user to enter two integer numbers x and y.
# The program should ask the user to select one of the following operations and display the results back.
# This are the options
# 1- Sum numbers
# 2- Subtract numbers
# 3- Multiply numbers
# 4- Divide numbers
# 5- Remainder of numbers
# 6- Compare numbers
# 7- Exit

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

x = float(input(‘Enter 1st number: ‘))
y = float(input(‘Enter 2nd number: ‘))
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’

selection = input(‘Please enter a selection: ‘)
if selection ==1:
print ‘The sum of’, x,’and ‘, y, ‘is’, xy1(x,y)
elif selection ==2:
print ‘The diffrence of’, x,’and’, y,’is’, xy2(x,y)
elif selection ==3:
print ‘The product of’, x,’and’, y,’is’, xy3(x,y)
elif selection ==4:
print ‘The quotient of’, x,’and’, y,’is’, xy4(x,y)
elif selection ==5:
print ‘The remainder of’, x,’and’, y,’is’, xy5(x,y)
elif selection ==6:

if x < y:
print x, ‘is less than’, y
elif x == y:
print x, ‘is equal to’, y
elif x > y:
print x, ‘is greater than’, y

Lab Description: While doing this lab it seemed pretty straight forward after obtaining the results from last week and was nice to see how a mathematical code runs.

Lab 3

Leave a Reply

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