2017-07-22 5 views
0

このエラーが発生し、必要なパラメータを満たしていると思っていますが、間違っていることとその誤りを正確にはわかりません。私はこのエラーを取得する:TypeError例外:addQuiz()不足している1つの必要な位置引数:「スコア」TypeError:addQuiz()missing 1必要な位置引数: 'score'

これは私が学生のために作成したクラスです。

class Student: 
    def __init__(self, name): 
     self.name = name 
     self.score = 0 
     self.counter = 0 

    def getName(self): 
     return self.name 

    def addQuiz(self, score): 
     self.score += score 
     self.counter += 1 

    def get_total_score(self): 
     return self.score 

    def getAverageScore(self): 
     return self.score/self.counter 


from Student import Student 

x = input("Enter a student's name: ") 


while True: 

    score = input("Enter in a quiz score (if done, press enter again): ") 
    quiz_score = Student.addQuiz(score) 
    if len(score) < 1: 
     print(Student.getName(x), Student.get_total_score(quiz_score)) 
     break 

答えて

2

Edit

これらのメソッドは、クラスメソッドではありません、インスタンスを作成し、インスタンスメソッドであり、それらを呼び出す:

をまた、その上でより良い外観を取って、あなたは問題の別の並べ替えを持っていた、私がコメントします:

class Student: 
    def __init__(self, name): 
     self.name = name 
     self.score = 0 
     self.counter = 0 

    def getName(self): 
     return self.name 

    def addQuiz(self, score): 
     self.score += score 
     self.counter += 1 

    def get_total_score(self): 
     return self.score 

    def getAverageScore(self): 
     return self.score/self.counter 

###execution part (you can put it in a main... but as you want) 


name = input("Enter a student's name: ") #create a variable name, and give it to the object you will create 
student_you = Student(name) #here, the name as parameter now belongs to the object 
score = float(input("Enter in a quiz score (if done, press enter again): ")) #you have to cast the input to a numerical type, such as float 

while score > 1: #it is better to the heart of the people to read the code, to modify a "flag variable" to end a while loop, don't ask in a if and then use a break, please, just an advice 
    score = float(input("Enter in a quiz score (if done, press enter again): ")) #here again, cast to float the score 
    student_you.addQuiz(score) #modify your object with the setter method 


print(student_you.getName(), student_you.get_total_score()) #finally when the execution is over, show to the world the result 
+0

変更とアドバイスをありがとうございます。私は何が起こっているのか分かりますが、私が今得ている問題(私がwhileループを終了したいときに私が再び入力を押していると信じています)はValueErrorです:文字列を浮動小数点に変換できませんでした: –

+0

これを解決するためにしてください。すべてを変更する必要があるのか​​、それとも簡単な解決策がありますか? –

+0

@HoonLeeよく、 "enter"キーを押すと、文字列、空の文字列 ""を送りますが、それは浮動小数点ではありません。ifまたはexeptionを追加することで醜いことができますが、ユーザーが悪い入力を書いた場合に何を期待しているのか分かりません –

関連する問題