我正在嘗試編寫一個程序,該程序?qū)⒔邮蛰斎?、運(yùn)行一些計(jì)算并將它們存儲在列表中,然后再添加列表的元素。但我不斷收到錯誤:wh_list = wh_list.append(wh) AttributeError: 'NoneType' object has no attribute 'append'代碼:wh_list = []u = len(wh_list)if u <= 1: while True: inp = input("Y or N:") B = int(input("B value:")) C = int(input("C value:")) D = int(input("D value:")) wh = B * C * D wh = int(wh) wh_list = wh_list.append(wh) if inp == "Y": breakelse: Ewh = sum(wh_list) print(Ewh)
1 回答

交互式愛情
TA貢獻(xiàn)1712條經(jīng)驗(yàn) 獲得超3個贊
append
更改列表并返回None
. 因此,
wh_list = wh_list.append(wh)
將要
附加
wh
到wh_list
分配
None
給wh_list
在下一次迭代中,它將中斷,wh_list
不再是列表。
相反,只寫
wh_list.append(wh)
添加回答
舉報(bào)
0/150
提交
取消