Python 循环时保留列表项

Python 循环时保留列表项,python,list,Python,List,因此,我想在这里为我的加法列表保存循环每个循环中的所有求和结果:: def calc (): addition = [] sub = [] multi = [] division = [] firstNumber =float(input("Enter the first number: \n")) oper =input("choose the operation (+ , - , * , /) \n") secondNumber =float(input("Enter the

因此,我想在这里为我的加法列表保存循环每个循环中的所有求和结果::

def calc ():

 addition = []
 sub = []
 multi = []
 division = []
 firstNumber =float(input("Enter the first number: \n"))
 oper =input("choose the operation (+ , - , * , /) \n")
 secondNumber =float(input("Enter the second number: \n"))

 if oper == "+":
     x = firstNumber + secondNumber
     addition.append(x)
     print(x)
     print(addition)
 elif oper == "-":
        firstNumber - secondNumber
 elif oper == "*":
        firstNumber * secondNumber
 elif oper == "/":
    if secondNumber != 0:
        firstNumber / secondNumber
    else:
        print("Can't divide by zero")

while 0<1:
 calc()
 msg = input("Do you want to continue? y/n")
 if msg == "y":
    calc()
 elif msg =="n":
    break
 else:
    print("wrong choise")
def calc():
加法=[]
sub=[]
多重=[]
除法=[]
firstNumber=float(输入(“输入第一个数字:\n”))
oper=输入(“选择操作(+、-、*、/)\n”)
secondNumber=float(输入(“输入第二个数字:\n”))
如果oper==“+”:
x=第一个数字+第二个数字
添加.附加(x)
打印(x)
打印(添加)
elif oper==“-”:
第一个号码-第二个号码
elif oper==“*”:
第一个号码*第二个号码
elif oper==“/”:
如果第二个号码!=0:
第一个号码/第二个号码
其他:
打印(“不能被零除”)

while 0将所有代码都保留在while循环中,除了代码的前4行。

您有2个选项:1)您可以添加
加法
列表作为函数参数,并在函数末尾返回它2)使
加法
在全局变量中列出全局变量存储
加法
,或传递它,每次调用
calc
时,else列表都会重置,非常感谢大家!在这里您可以看到要继续吗?消息被跳过一次,为什么??