Python 編碼新手在這里。我知道可能還會出現此錯誤的其他實體,并且我已嘗試在堆疊溢位時讀取它們,但對于我而言,以我的經驗水平解碼似乎太技術性了。有人可以幫助解釋為什么這不起作用嗎?我正在嘗試使用 while 回圈來要求用戶輸入一個數字。列印用戶輸入的所有數字的總和,如果用戶輸入 0,則中斷 while 回圈。
total = []
i = 1
total = int(input('enter a number:'))
while i in total > 0:
total = int(input('enter a number:'))
total = total i
if i == 0:
break
uj5u.com熱心網友回復:
while i in total > 0:
使用運算子鏈接規則進行決議,這使其等效于:
while i in total and total > 0:
問題在于total > 0測驗;total是 a list,它正在嘗試進行字典比較。你的另一個問題是:
total = total i
list's 不能與int.
固定代碼如下所示:
total = 0 # total should be an int, not a list to accumulate the sum
while True: # The if check at the end makes it pointless to test or initialize i up front
i = int(input('enter a number:'))
total = i
if i == 0:
break
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/411452.html
標籤:
下一篇:瓷磚圖不顯示
