+ 3

Can someone help me inspect the error in this code, anytime I run it it returned an error. [SOLVED]

class Player: def init(self, name, level): self.name = name self.level = level def intro(self): print(self.name + " (Level " + self.level + ")") name=input() level=input() p=Player(name,level) p.intro()

29th Apr 2022, 1:47 AM
Sokkai
Sokkai - avatar
12 Respuestas
29th Apr 2022, 2:50 AM
Sokkai
Sokkai - avatar
+ 6
YIPMONG there should be double underscore before and after........ You have entered only single
29th Apr 2022, 2:48 AM
Sanjyot21
Sanjyot21 - avatar
+ 4
YIPMONG you forgot the double underscore before and after init. Use def __init__ (self,name,level). It should work fine.
29th Apr 2022, 2:29 AM
Sanjyot21
Sanjyot21 - avatar
+ 2
Sanjyot21 i did put that and it still returned an error
29th Apr 2022, 2:40 AM
Sokkai
Sokkai - avatar
+ 2
YIPMONG can you share that code
29th Apr 2022, 2:43 AM
Sanjyot21
Sanjyot21 - avatar
29th Apr 2022, 2:46 AM
Sokkai
Sokkai - avatar
+ 1
YIPMONG you're welcome
29th Apr 2022, 2:52 AM
Sanjyot21
Sanjyot21 - avatar
+ 1
Only you need to correct init with __inint__
29th Apr 2022, 5:58 AM
Ashwin Kumar
Ashwin Kumar - avatar
+ 1
Bro __init__ write like this
30th Apr 2022, 1:28 AM
SHAIK ABDULHAMEED
SHAIK ABDULHAMEED - avatar
+ 1
Your constructor has syntax error
30th Apr 2022, 4:33 PM
Ikram Arshad
Ikram Arshad - avatar
+ 1
class Player: def __init__(self,name,level): #here you did a mistake self.name=name self.level=level def intro(self): print(self.name, "level", self.level). #here you did a mistake, you cant add string to integer, to print use (,) comas name=input() level=input() p=Player(name,level) p.intro()
30th Apr 2022, 8:14 PM
PRAKASH KUMAR
PRAKASH KUMAR - avatar
0
Can anyone please explain to me why we use __inint__
28th Jun 2022, 7:37 AM
Ashwin Kumar
Ashwin Kumar - avatar