(9/10)

Pet Simulator Setup — Python typing lesson

Set up a pet simulator using classes and object-oriented design.

What you'll practice

Let's start our final project: a Pet Simulator! First, we need to build the Pet class with hunger and a way to feed it.

  • We add a `hunger` property inside `__init__` and give it a starting value.
  • The `feed` method lowers the pet's hunger.

Pro Access Required

This is a premium lesson. Upgrade to Pro to unlock this interactive exercise and continue your learning journey.

🐍Python

Pet Simulator Setup

0 WPM
0% Accuracy
0:00 Time elapsed
1
2
3
4
5
6
7
8
9
10
class Pet:↵
def __init__(self, name):↵
self.name = name↵
self.hunger = 5↵
↵
def feed(self):↵
self.hunger = self.hunger - 1↵
print(self.name + ' has been fed!')↵
↵
print('Pet blueprint is ready for the game!')
0 / 239
Press This!
👇
`~
1!
2@
3#
4$
5%
6^
7&
8*
9(
0)
-_
=+
⌫
⇥
Q
W
E
R
T
Y
U
I
O
P
[{
]}
\|
⇪
A
S
D
F
G
H
J
K
L
;:
'"
↵
⇧
Z
X
C
V
B
N
M
,<
.>
/?
⇧
Thumb
Index
Middle
Ring
Pinky