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())

11th Jun 2022, 5:16 PM
shifa
shifa - avatar
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.
11th Jun 2022, 5:34 PM
Lisa
Lisa - avatar
+ 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__
11th Jun 2022, 8:19 PM
Lisa
Lisa - avatar
+ 1
And you may need to fix your indentation https://code.sololearn.com/cRQ0KP20Uieo/?ref=app
11th Jun 2022, 8:24 PM
Lisa
Lisa - avatar
0
Thanks
11th Jun 2022, 5:48 PM
shifa
shifa - avatar
0
But even after making this improvement the code is not working
11th Jun 2022, 8:17 PM
shifa
shifa - avatar
0
Shouldnt it be tmarks:int not tmarks=int?
13th Jun 2022, 3:51 PM
Stefan Corneteanu
Stefan Corneteanu - avatar