0
Why is my code not working. spot the error and tell me the correction. Would be immensely grateful
class Student: def __init__(self, name: str, tmarks = int, subjects = 0): self.name = name self.tmarks = tmarks self.subjects = subjects def calculateAvg(self): return(tmarks/subjects*100) student1 = Student("shifa", 800, 8) print(student1.calculateAvg())
6 ответов
+ 3
class Student:
def __init__(self, name: str, tmarks = int, subjects = 0):
self.name = name
self.tmarks = tmarks
self.subjects = subjects
def calculateAvg(self):
return(self.tmarks/self.subjects*100)
student1 = Student("shifa", 800, 8)
print(student1.calculateAvg())
# you need to use "self" when referring to the attributes of tmarks and subjects.
+ 1
class Student:
def __init__(self, name, tmarks, subjects):
self.name = name
self.tmarks = tmarks
self.subjects = subjects
def calculateAvg(self):
return(self.tmarks/self.subjects*100)
student1 = Student("shifa", 800, 8)
print(student1.calculateAvg())
# look at the __init__
+ 1
And you may need to fix your indentation
https://code.sololearn.com/cRQ0KP20Uieo/?ref=app
0
Thanks
0
But even after making this improvement the code is not working
0
Shouldnt it be tmarks:int not tmarks=int?