【发布时间】:2015-09-26 17:29:28
【问题描述】:
def add(a,b):
return a+b
print(a+b)
def subtract(a,b):
return a-b
print(a-b)
def multiply(a,b):
return a*b
print(a*b)
def divide(a,b)
return a/b
print(a/b)
print('Please select an operation:')
print('1.Add')
print(2.Subtract')
print(3.Multiply')
print(4.Divide')
choice=input('Enter a choice\'1/2/3/4\')
a=int(input('Enter first number')
b=int(input('Enter second number')
if choice=='1':
#these are the sections that arent working
add(a,b)
elif choice=='2':
#when run, it wont print the function even though Ive called it
subtract(a,b)
elif choice=='3':
multiply(a,b)
elif choice=='4':
divide(a,b)
如果有人能提供解决方案,我将不胜感激。谢谢
【问题讨论】:
-
return立即离开一个函数。在前四个函数的print语句之后,您需要return。 -
哦,好的。谢谢;这帮助很大。