如何列出函数的结果(python)
我想列出从numberA中获得的总和。如何列出函数的结果(python)
功能“添加”提示用户是否需要添加。如果他选择是,那么它将转到功能“numberA”。这部分将循环。
我想在用户在函数“add”中选择“N”时列出总和列表。最后再总结一遍所有的金额。
我不知道如何来存储从“numberA”的取值
def numberA():
num1=int(input("Enter First Number"))
num2=int(input("Enter Second Number"))
total=num1+num2
print("The total: ", total)
def add():
userSelect = input("Do You Want to Add?"
"\n(Y) Yes ; (N) No"
"\n")
while userSelect != "Y" and userSelect != "N":
print("Error")
add()
if userSelect == "Y":
numberA()
add()
else:
print("Bye")
add()
list = [add()] #List of the Sums go here
for each in list:
print(each)
total = []
def numberA():
num1=int(input("Enter First Number"))
num2=int(input("Enter Second Number"))
total.append(num1+num2)
def add():
userSelect = input("Do You Want to Add?"
"\n(Y) Yes ; (N) No"
"\n")
while userSelect != "Y" and userSelect != "N":
print("Error")
add()
if userSelect == "Y":
numberA()
add()
else:
print("Bye")
add()
print("The total: ")
for each in total:
print(each)
这工作。谢谢!还有一件事...有没有办法得到打印的数字的总和? –
谢谢!!!!!! –
如何以这种方式列出: 您的总数是:1,2,3和4.这些总数之和是:10. 这些数字用逗号分隔,最后一个数字用“和”分隔。 。 谢谢 –
此帮助
def add():
ask = True
res = []
while ask :
num1=int(input("Enter First Number : "))
num2=int(input("Enter Second Number : "))
total = num1+num2
userSelect = input("Do You Want to Add?"
"\n(Y) Yes ; (N) No"
"\n")
if userSelect not in ['Y', 'N']:
print "Error"
elif userSelect == 'Y':
ask = True
else :
ask = False
res.append(total)
return res
print add()
回报从功能价值,不打印的价值 –