我被分配到記錄學生的分數爲數學測驗數學測驗 - 海峽對象沒有屬性
下面一個任務是我的任務:
老師想用學生的成績通過這些測驗來記錄他們的表現。系統應該爲每個學生存儲>最後三個分數。
每次我我的代碼運行時我收到錯誤: AttributeError的:「海峽」對象有沒有屬性「追加」
,當我轉換成一個int我得到這個錯誤: int()函數參數必須是字符串,類似字節的對象或數字,而不是'NoneType'
import csv
import os
name = input("enter your name: ")
classroom_num = input("enter your classroom number: ")
score = 5
print ("%s, you scored %d/10 questions correctly"%(name,score))
status = open ("state.txt","w") #Every time program is run +1 is added, so that column 1-3 are updated
with open ("state.txt","r") as f:
state = f.read()
if os.stat("state.txt").st_size == 0:
status.write ("0")
state_ints = [ int(x) for x in state.split() ] #converts into int
addone = 1
if state_ints == 3: #If program is run more than 3 times the value in text file reset to 0
state_ints = 0
status.write (state_ints)
with open("Classroom {}.csv".format(classroom_num),"a+") as f:
rows = csv.reader(f)
for row in rows:
if row in rows in row[0] != (name) in row: #Checks if name exists in file (if so name isn't appended to column)
state_ints.append(addone) #Adds one everytime program is run so that score can be replaced for row 1-3
status.write (state_ints)
name_row = (row [0])
name_row.append(name)
score_row = (row (state_ints))
score_row.append(score)
else:
state_ints.append(addone)
status.write (state_ints)
score_row = (row [state_ints])
score_row.append(score)
status.close()
另外還有什麼其他的錯誤呢?我能做些什麼才能使這個任務更高效和完成?
'state_ints = state_ints.append(addone)' - 我建議您查看有關'append'的課程資料。 – TigerhawkT3
恐怕「修復我的代碼中的所有錯誤」並不是足夠具體的問題成爲SO的主題。 – TigerhawkT3