は私の仕事ではありませんしています数学クイズ - strのオブジェクトは、私は以下</p> <p>数学クイズのための学生のスコアを記録するために、タスクを割り当てられてきた無属性
教師が生徒からの結果を使用したいです彼らのパフォーマンスを記録するためにこれらのクイズを取る。システムは、各生徒の最後の3つの得点を保存する必要があります。
私は私のコードを実行するたびに、私はエラーが表示されます。 はAttributeError:「str」はオブジェクトが属性を持っていない
「を追加」と私は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