0

why i am getting this error in python? Can anyone explain?

This below code executes perfectly. But when i place if-elif-else ladder below init i.e outside of init method I am getting error named "NameError: name 'Warrior' is not defined". Why i am getting that error can anyone help me to sort it out. This is the code. https://code.sololearn.com/cYz1lPrup1TY/#py

30th Jan 2020, 8:33 AM
Dileep Patcha
Dileep Patcha - avatar
2 Antworten
+ 1
Because you already initialize the Warrior object with __init__(self). So, 'Warrior' in if-else statement mean Warrior object, not Warrior class. Replace 'Warrior' with 'self' in if- statement, it'll be the same. If you put off if-else statement outside of init method, it'll throw error because there is no name 'Warrior' in the scope of Class Warrior. I hope it clear :)
30th Jan 2020, 9:07 AM
The Sylar
0
Yes my doubt is clarified. Thank you Mr. Sylar
30th Jan 2020, 7:54 PM
Dileep Patcha
Dileep Patcha - avatar