Monday, January 5, 2009

Math

import sys
import math
def MenuMsg():
print "Select an option from the menu:"
print "1: add a number"
print "2: multiply a number"
print "3: subtract a number"
print "4: divide a numer"
choice=input("Enter your selection here: ")
return choice

def ProcessChoice(choice,x,y):
if(choice == 1):
ans=x+y
elif(choice == 2):
ans=x*y
elif(choice == 3):
ans=x-y
elif(choice == 4):
if(y == 0):
print "can't divide by 0"
else:
ans=x/y
return ans
choice=MenuMsg()
num1=input("Enter the 1st whole number here: ")
num2=input("Enter the 2nd whole number here: ")
ans=ProcessChoice(choice,num1,num2)
print "The answer is %d" % ans
quit=input("Enter a 1 and then hit enter: ")

No comments:

Post a Comment