Question
Do a class, and I'm stucked in get_inventory(self) class Trainer A class representing a pokemon trainer. A trainer can have 6 Pokemon at maximum. Notes
Do a class, and I'm stucked in get_inventory(self)
class Trainer
A class representing a pokemon trainer. A trainer can have 6 Pokemon at maximum.
Notes
- The current pokemon should be kept track of with an instance variable representing the index of the currently selected Pokemon.
Create an instance of the Trainer class.
Parameters
- name: The name of the trainer.
Methods
def __init__(self, name:str) >None
Create an instance of the Trainer class.
Parameters
- name: The name of the trainer.
def get_name(self) >str
Return the trainer's name.
def get_inventory(self) >Dict[Item,int]
Returns the trainer's inventory as a dictionary mapping items to the count of that item remaining in the dictionary.
def get_current_pokemon(self) >Pokemon
Gets the current pokemon, or raises a NoPokemonException if the trainer doesn't have a single pokemon.
def get_all_pokemon(self) >List[Pokemon]
Returns the trainer's pokemon.
- The order of the pokemon in the list should be the order in which they were added to the roster.
- Modifying the list returned by this method should not affect the state of this instance.
def rest_all_pokemon(self) >None
Rests all pokemon in the party
def all_pokemon_fainted(self) >bool
Return true iff all the trainer's pokemon have fainted.
def can_add_pokemon(self, pokemon:Pokemon) >bool
Returns true iff the supplied pokemon can be added to this trainer's roster.
You shouldn't be able to add the same pokemon instance twice or more than the maximum amount of pokemon for a trainer.
def add_pokemon(self, pokemon:Pokemon) >None
Adds a new pokemon into the roster, assuming that doing so would be valid.
If there were no Pokemon in the roster prior to calling this method, set the current pokemon to the one that was added.
def can_switch_pokemon(self, index:int) >bool
Determines if the pokemon index would be valid to switch to, and returns true iff the switch would be valid.
You cannot swap to a pokemon which is currently out on battle, or which has fainted.
Parameters
- index: The index of the next pokemon in the roster.
def switch_pokemon(self, index:int) >None
Switches pokemon to the one at the supplied index, assuming that the switch is valid.
Parameters
- index: The index of the pokemon to switch to.
def add_item(self, item:Item, uses:int) >None
Adds an item to the trainer's inventory and increments its uses by the supplied amount.
Parameters
- item: The item to add.
- uses: The quantity of the item to be added to the inventory.
Examples
>>> food = Food("Burger King Foot Lettuce", 20) >>> ash.get_inventory() {} >>> ash.add_item(food, 1) >>> ash.get_inventory() {Food('Burger King Foot Lettuce'): 1} >>> ash.use_item(food) >>> ash.get_inventory() {} >>> ash.add_item(food, 3) >>> ash.add_item(food, 4) >>> ash.get_inventory() {Food('Burger King Foot Lettuce'): 7}
def has_item(self, item:Item) >bool
Returns true if the item is in the trainer's inventory and has uses.
def use_item(self, item:Item) >None
If the item is present in the trainer's inventory, decrement its count. Removes the item from the inventory entirely if its count hits 0.
def __str__(self) >str
Returns a string representation of a Trainer
def __repr__(self) >str
Returns a string representation of a Trainer
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started