Lab 3

Lab 3

Lab description:

Re-write lab #2 this time using functions. Your program should display a menu to the user with the following options: 1-      Sum numbers

2-      Subtract numbers

3-      Multiply numbers

4-      Divide numbers

5-      Remainder of numbers

6-      Compare numbers

7-      Exit

This is the program:

# Viralkumar Mistry
# Lab 3 – Functions
# Section: 9306
# Date: 3/7/13

# 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

Screen shot of result: