Reputation: 43
I'm getting this error and I thought I fulfilled the parameters needed but I'm not sure what I'm doing wrong and what this error exactly means. I get this error: TypeError: addQuiz() missing 1 required positional argument: 'score'
This is the class that I created for the student:
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
Upvotes: 0
Views: 1331
Reputation: 16224
Edit
Those methods are not class methods, are instance method, make an instance, and call them:
Also, taking a better look on it, you had another sort of problem, I will comment:
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
Upvotes: 2