Welcome to this week's Python challenge! π
In this challenge, youβll be creating a virtual pet using Object-Oriented Programming concepts in Python. This fun project will help you practice how to use classes, attributes, methods, and constructors.
Create a class called Pet with the following:
name: the name of your pethunger: an integer representing hunger level (0 = full, 10 = very hungry)energy: an integer representing energy level (0 = tired, 10 = fully rested)happiness: an integer (0β10)
eat(): reduces hunger by 3 points (but not below 0), and increases happiness by 1.sleep(): increases energy by 5 points (but not above 10).play(): decreases energy by 2, increases happiness by 2, and increases hunger by 1.get_status(): prints the current state of the pet.
- Add a method
train(trick)that teaches your pet a new trick and stores it in a list. - Add a method
show_tricks()that prints all learned tricks.
- Fork or clone this repo.
- Write your
Petclass inpet.py. - In
main.py, create a pet object and call its methods to test functionality. - Submit a GitHub repo or a zipped folder with your code and a screenshot of the output.
Creating pet: Max
Max is eating...
Max is playing...
Max is sleeping...
Max's current status:
Hunger: 2
Energy: 8
Happiness: 9
Tricks: ['roll over', 'play dead']
### π‘ Tips
Use max() and min() to keep values between 0 and 10.
Think about edge cases like trying to play when energy is 0.
π Submission
Deadline: [Set your date]
Submission format: clone / fork this repo
Bonus points for creativity (custom actions, emojis, pet types, etc.)