« All Events
5 PM – Python OOP – Bill
February 13, 2023 @ 5:00 pm - 6:00 pm
Today We:
- Reviewed Classes and Instances
- Learned about using instance variables in lists and dictionaries
Your HW:
- Create a new file called “Feb_13_ClassesHerosPractice”
- Create a Hero Class with the following attributes:
- Name
- Power
- Give it a default attribute called villains defeated
- Give the class the following methods:
- display – no parameters – returns the following string:
- “<name> has <power> powers and has defeated <villains defeated> villains”
- defeat a villain – 1 parameter: villain
- Prints out the following statement: “<name> has defeated <villain>!”
- Increment the villains defeated attribute by 1
- Create a list called hall_of_justice
- Fill it with the following Heroes: Batman, Superman, Wonder Woman, flash, cyborg
- Using the list, have Superman defeat a villain “Zod”
have Batman defeat a villain “Joker”
- Loop through the list and display each Hero’s information
- Loop through the list and have each Hero defeat a villain “Darkseid”
- Loop through the list one more time like in step 8 to check all of their villain’s defeated attributes
- If you are confused about anything or need help send an email to billhan@ayclogic.com