[英]How do I gather information from each loop in a while loop python
我想在每次循環時從 while 循環中收集信息。 例如,如果您有一個永遠運行的 while 循環並包含一個要求輸入數字的輸入,並且您隨着時間的推移添加數字,我應該怎么做? 例子:
while True:
a = int(input("Enter a number "))
a = a + a
有沒有辦法做到這一點? 太感謝了!
total = 0
while True:
a = int(input("Enter a number "))
total = total + a
print(f"The total is {total}")
total = 0
while True:
a = int(input("Enter a number"))
total = total + a
print("The sum is ", sum)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.