Why output "TypeError" | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why output "TypeError"

# My code as bellow: class Scores(): def __index__(self,math,english): self.math=math self.english=english def __add__(self, other): return Scores(self.math+other.math , self.english+other.english) joe=Scores(70,85) vivi=Scores(99,77) result=joe+vivi print(result.math) # Output: Traceback (most recent call last): File "/Users/linjoe/PycharmProjects/Joe's pratice/Boolean.py", line 9, in <module> joe=Scores(70,85) TypeError: Scores() takes no arguments

4th Apr 2019, 11:43 AM
Joe Lishuai Lin
Joe Lishuai Lin - avatar
1 Answer
+ 2
You need to use 'init' instead of 'index'.
4th Apr 2019, 11:48 AM
HonFu
HonFu - avatar