+ 3

Whats wrong with this

I am trying to use magic Methods for first time, plz bare with me. I don't want to go further lessons without making this one work. I think it's some silly mistake, I googled it but nothing https://code.sololearn.com/cmtB2CPKSK4n/?ref=app

4th Nov 2018, 7:30 AM
Dhairyashil Deshpande
Dhairyashil Deshpande - avatar
7 Antworten
+ 10
A couple of things: 1. the magic method is __add__ and you have to define it within the class 2. Also, it has to match the npc attributes and has to stay consistent 3. If you want to make the .group parameter optional, use asterisk Check out how I changed it: https://code.sololearn.com/cluUW7ojH2G6/?ref=app
4th Nov 2018, 7:46 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 4
Dhairyashil Deshpande Yes, because the class declaration as you wrote it makes the npc class inherit (being derived) from str. And that may not neccesarily be compatible in this case. Also, probably not what you wanted in the first place :)
4th Nov 2018, 8:00 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 1
ok I saw your modification,,, thank you very much for clearing that up,,,,, your are great,, thank you
4th Nov 2018, 8:07 AM
Dhairyashil Deshpande
Dhairyashil Deshpande - avatar
0
it gives error decoding str not supported
4th Nov 2018, 7:56 AM
Dhairyashil Deshpande
Dhairyashil Deshpande - avatar
0
what changes do you suggest If I want an output of "general general" "british scottish"
4th Nov 2018, 8:04 AM
Dhairyashil Deshpande
Dhairyashil Deshpande - avatar
0
I want to add, class attributes by using magic methods
4th Nov 2018, 8:04 AM
Dhairyashil Deshpande
Dhairyashil Deshpande - avatar
0
Thank you for your help
4th Nov 2018, 8:05 AM
Dhairyashil Deshpande
Dhairyashil Deshpande - avatar