-1
,所以我想在這裏我除了列表保存所有的總和導致循環::保持列表中的項目,而循環
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")
所以,如果我的第一相加結果是5,第二個是每個週期10 ... 加入列表是[5,10,...]
你有2種選擇:1)你可以加上'addition'列表作爲函數參數和功能2月底返回它)使'addition'列表中的全局變量 – Arman
店'addition'在一個全局變量或傳遞,其他列表重置每次你調用'calc' –
非常感謝你們! – ProgrammerToBe