(10/10)

Pet Simulator Game Loop — Python typing lesson

Create an interactive game loop for your pet simulator.

What you'll practice

Let's bring our pet to life with a game loop! The game will run as long as the pet is not too hungry.

  • We use a `while` loop to keep the game running.
  • We get the user's choice with `input()`.

Pro Access Required

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

🐍Python

Pet Simulator Game Loop

0 WPM
0% Accuracy
0:00 Time elapsed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Pet:↵
def __init__(self, name):↵
self.name = name↵
self.hunger = 5↵
def feed(self):↵
self.hunger = self.hunger - 1↵
↵
my_pet = Pet('Typy')↵
↵
while my_pet.hunger > 0:↵
print(my_pet.name + "'s hunger is " + str(my_pet.hunger))↵
choice = input('Type feed or wait: ')↵
if choice == 'feed':↵
my_pet.feed()↵
↵
print(my_pet.name + ' is full and happy!')
0 / 390
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