I want to have a instance, which the user can access using an input()statement.
Here are my three instances
water1 = waterType("squirtle", 50)
grass1 = grassType("bulbasaur", 50)
fire1 = fireType("charmander", 50)
Here's what I mean
class waterType(Pokemon):
"""creates a water pokemon"""
pokemon_type = "water"
damage = 10
def __init__(self, name, hp):
self.name = name
self.hp = hp
def growl(self):
print("Splish Splosh")
def attack(self):
enemy = input("Who do you want to attack?") <--- over here, I would enter "fire1"
"""attribute error occurs here"""
if (enemy.pokemon_type == "fire"):
global damage
water1.damage = water1.damage*2
enemy.hp = enemy.hp - water1.damage
return enemy.hp
print ("It was super effective!")
print (enemy.hp)
If I take all the "enemy" and replace it with "fire1", everything works perfectly. However, then I would need to manually input every single fire-type instance.
If it is not possible to assign an instance to an input, is there any way to fix my code?