- This event has passed.
7:00 PM – Python OOP – Joshua
November 6 @ 7:00 pm
Today We Did
– Reviewed Robux + Practice Classes
Homework
- Add a function called “Add_animal” to your zoo application
- Uses Inputs to create a new animal
- Add it to your self.animal_dict
- Don’t for get to add an “add” option to your menu and your application loop
class Animal:
def __init__(self, name,species, color):
self.name = name
self.species=species
self.color=color
import random
class Zoo():
def __init__(self):
self.menu ="""
1. Pet a random animal
2. Exit
Choose your Selection"""
self.animal_dict= {"1":Animal("jerry","dog","blue")}
def application_loop(self):
while True:
selection = input(self.menu)
if selection == "1":
random_animal= random.choice(self.animal_dict.values())
print(f"You pet {random_animal.name} the {random_animal.color} {random_animal.species}.")
if selection == "2":
break
my_zoo= Zoo()
my_zoo.application_loop()