Python Forum
Print Player Name and Number of Pokemon
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Print Player Name and Number of Pokemon
#2
How is it not working? Does your program crash with an error message? If so, please post the error message. The code you've posted does not run. Your are missing Player.save() and Player.load() methods. When I remove the game code that saves and loads player 1, the program appears to work. This command:
print(player1.has_pokemon_left())
prints
Output:
True
next_pokemon() doesn't look right to me. I would expect that to return the next pokemon, not the first pokemon. Maybe writing an iterator that lets you loop through your pokemon is a future lesson.

This comment:
Quote:As a reminder, we can use the following code to overwrite the default str function of a class.
Is telling you wo write a __str__() method for your Player class so you get something better than:
Output:
<__main__.Player object at 0x0000022204EC1460>
when you print(player).

This comment:
Quote:However, whenever you have if A return True else return False , you should always just return A. So our code should be rewritten like this:
Is telling you to rewrite this:
    def is_alive(self):
        if self.health > 0:
            return True
        else:
            return False
I'm telling you that there is no need to have this method defined in each of your Pokemon subclasses. It should be in the Pokemon class, and Pikachu and others should inherit the method. Maybe that is also a later lesson.
Reply


Messages In This Thread
RE: Print Player Name and Number of Pokemon - by deanhystad - Aug-23-2022, 08:54 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  print two different sequence number mantonegro 2 1,684 Nov-16-2020, 06:19 PM
Last Post: mantonegro
  Print the number of items in a list on ubuntu terminal buttercup 2 1,957 Jul-24-2020, 01:46 PM
Last Post: ndc85430
  Beginner Code, how to print something after a number of turns (guessing game) QTPi 4 2,762 Jun-18-2020, 04:59 PM
Last Post: QTPi
  Print 'X' a number of times Than999 1 2,666 Jan-18-2020, 06:41 PM
Last Post: Larz60+
  how do I make a number only print once but the number keeps on decreasing? syafiq14 5 2,992 Jan-03-2020, 10:34 AM
Last Post: perfringo
  print number of a list line per line lateublegende 2 2,735 Mar-20-2019, 04:07 PM
Last Post: lateublegende
  How to get number with print statement Rehan11 1 2,301 Jul-28-2018, 02:01 PM
Last Post: buran
  How to print number from user Rehan11 5 3,517 Dec-03-2017, 03:52 PM
Last Post: Larz60+
  print floating point number Regulus 19 11,268 Aug-14-2017, 02:42 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020