- This event has passed.
7:00 PM -Python OOP – Joshua
October 2 @ 7:00 pm
Today We Did
– Minion class
– How do I use return with classes
– How to work with classes without inputs /class variables
– How to have objects work together/send eachother data.
Homework
-
conriotuorhtis <——- Kurt you know why this is here
- Page 167 – TRY IT YOURSELF
import random # random.randint(1,100) <------- gets a random number between 1-100 # random.choice(list_name) gives you a random from the list class Minion: def __init__(self): self.hp = 100 self.attack = 30 self.defense = 1 self.cool_attack_names=["Butter Beatdown", "Popcorn parry", "Corn on the cob crash"] def take_damage(self, damage_amount): self.hp -= (damage_amount -self.defense) print(f"The minion took {damage_amount} damage. ") if self.hp <= 0: print("You defeated the minion") print("He died a kinda disappointing death") # create a function call deal damage # you will check the number attack the minion has # and return a number between 1 and the attack number # add a cool attacking move name def deal_damage(self): damage_sent = random.randint(1,self.attack) print(random.choice(self.cool_attack_names)) return damage_sentTo the above code, I want you to add a function called loot.
1. You are going to check if the hp is less than 1
2. If so, you will return a random loot item from a list you create