American Young Coder (AYC)

AYC logo
Loading Events

« All Events

  • This event has passed.

12 PM – Python OOP – Joel

June 29 @ 12:00 pm - 1:00 pm

Today we did:
  1. We learned about OOP concepts and how they work in Python.
  1. Make a new file called Make a new class called Animal. The class will have 4 attributes: name, species, age, and sound. It will also have 3 methods: make_sound, describe, and age_in_human_years:
  2. The make_sound method will have no parameters (except self). Inside the method, it will display: “<name> the <species> makes a <sound> sound”. Replace <name> with that animal’s name, and do the same thing for the rest.
  3. The describe method is simple with no parameters: simply display “<name> is a <age>-year-old <species>.
  4. The age_in_human_years method once again has no parameters. Inside, it checks if the animal’s species is a “cat”. If it is, then it will return the age of the animal * 15 (mutliplied by 15). Otherwise, if the species is “dog”, then it will return the age of the animal * 7 (multiplied by 7). Finally, else it will return the age of the animal * 4 (multiplied by 4).
  5. Now, outside of the class, make three animals and fill in their name, species, age, and sound. For example, you can make a dog named Fred, aged 7 and makes a ‘woof’ sound.
  6. Make an animals list and append those 3 animals you created into that list.
  7. Now, loop through the list, and call the make_sound method for each animal.
  8. Make another for loop and call the describe function for each animal in the list.
  9. Finally, make one last for loop, and call the animal’s age_in_human_years method and set that to a variable called human_years. Then, print “<name> is <human_years> human years old”.

If you have any questions, feel free to email me at


June 29
12:00 pm - 1:00 pm
Verified by MonsterInsights