Welcome 🙂
Description:
This is my third project working with Python. This was a bit more challenging than others due to the different functions this code has to execute. But I was able to debug and get this code running smoothly!
Code:
def sum(x,y):
return (x + y)
def sub(x,y):
return (x – y)
def mult(x,y):
return (x * y)
def div(x,y):
return (x / y)
def rem(x,y):
return (x % y)
def comp(x,y):
while x != 0 and y != 0:
if x == y:
return True
if x < y:
return -1
elif x > y:
return 1
def menu_options():
print ‘Please select one of the following functions.’
print ‘[1] Add Numbers’
print ‘[2] Subtract Numbers’
print ‘[3] Multiply Numbers’
print ‘[4] Divide Numbers’
print ‘[5] Remainder Numbers’
print ‘[6] Compare Numbers’
print ‘[7] Exit’
menu_options()
num = input(‘Select your choice: ‘)
while num != 7:
x = input (‘enter x: ‘)
y = input (‘enter y: ‘)
if num == 1:
print sum(x,y)
if num == 2:
print sub(x,y)
if num == 3:
print mult(x,y)
if num == 4:
print div(x,y)
if num == 5:
print rem(x,y)
if num == 6:
print comp(x,y)
menu_options()
num = input (‘Select your choice: ‘)
Screenshot:
No comments