+ 2

Can anyone explain what's wrong with this code?

This is a simple RPG game using python https://code.sololearn.com/cfplMPH3yCfy/?ref=app

17th Nov 2023, 8:28 AM
Atharva Jangade
Atharva Jangade - avatar
4 Respuestas
+ 7
EOF error indicates that not all inputs have been entered before running the code, as per Sololearn requirements. External IDE's allow you full interactivity
17th Nov 2023, 9:01 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 5
Atharva Jangade , Add a "python" tag to your post. I like how compartmentalized and formal the code is. You even wrote a __str__ method. I copied it into Pydroid 3 so I could run it interactively. I have two suggestions. First, if saying no is an "invalid action", don't offer it to the player as a choice. Auto-turn the whole fight, since the only real choice for the player is to just keep typing yes, and save them the trouble. On the other hand, you could make saying no a valid action and let them heal or something. Maybe they become friends, because I notice the enemy never attacks unless the player does. Second, it doesn't really make sense to report damage in the attack_target method, since you're not sure any damage will occur. It should be reported in the take_damage method if damage occurs.
17th Nov 2023, 1:16 PM
Rain
Rain - avatar
+ 3
you need to run it in an interactive console. Not possible in Sololearn. The code seems ok. Not much interactivity except typing yes or no. Maybe it was just the start of a tutorial code from somewhere. if you want to test it in Sololearn type 6 lines of yes in the input box, then press the Submit button. yes yes yes yes yes yes Submit
17th Nov 2023, 12:53 PM
Bob_Li
Bob_Li - avatar
+ 1
The code looks generally fine, but there’s a potential issue in the take_damage method of the Character class. The line: self.health -= max(0, damage - self.defense) may lead to negative health if the damage is less than the defense. You might want to ensure that the health does not go below 0: self.health = max(0, self.health - max(0, damage - self.defense)) This modification ensures that the health won’t become negative.
9th Dec 2023, 2:39 AM
Jesse Cedillos
Jesse Cedillos - avatar