First to Twenty
Build the game.
First to Twenty is a free Coding for Kids lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Coding for Kids learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
First to Twenty! 🎮
Time for a real game! 🎲 Keep rolling and adding points. The first to reach 20 wins! 🏆
The Game Plan 📋
Our game will: start at 0, roll the dice, add points, and stop when we reach 20!
print('Goal: reach 20 points! 🎯')Set Up the Score 0️⃣
Start the points at zero.
points = 0
goal = 20
print('Score:', points, 'Goal:', goal)Keep Rolling With while 🔁
A while loop repeats UNTIL something happens. Keep rolling while points are under 20!
import random
points = 0
while points < 20:
points += random.randint(1, 6)
print('Reached:', points)Show Every Roll 👀
Print each roll so we can watch the score climb!
import random
points = 0
while points < 20:
roll = random.randint(1, 6)
points += roll
print('Rolled', roll, '- score', points)Win Message! 🥳
When the loop ends, you reached 20 — print a winner message!
import random
points = 0
while points < 20:
points += random.randint(1, 6)
print('You win with', points, 'points! 🥳')Count the Rolls 🔢
How many rolls did it take? Let's count!
import random
points = 0
rolls = 0
while points < 20:
points += random.randint(1, 6)
rolls += 1
print('Won in', rolls, 'rolls! 🎲')Player One Plays 🧑
Let Player 1 play their turn to reach 20.
import random
p1 = 0
r1 = 0
while p1 < 20:
p1 += random.randint(1, 6)
r1 += 1
print('Player 1 took', r1, 'rolls')Player Two Plays 🧑
Now Player 2 takes their turn!
import random
p2 = 0
r2 = 0
while p2 < 20:
p2 += random.randint(1, 6)
r2 += 1
print('Player 2 took', r2, 'rolls')Find the Winner 🥇
Fewest rolls to reach 20 wins! Compare the two players.
r1 = 5
r2 = 7
if r1 < r2:
print('Player 1 wins! 🥇')
else:
print('Player 2 wins! 🥇')The Whole Game! 🎮
Here's the full two-player game. Run it and see who wins! ✨
import random
def play():
points = 0
rolls = 0
while points < 20:
points += random.randint(1, 6)
rolls += 1
return rolls
p1 = play()
p2 = play()
print('Player 1:', p1, 'rolls')
print('Player 2:', p2, 'rolls')
if p1 < p2:
print('Player 1 wins! 🏆')
else:
print('Player 2 wins! 🏆')Quick Check ✅
Which loop keeps going UNTIL a condition is met?
Game Maker! 🏆
WOW! You built a real game! You learned to:
- Use a
whileloop to keep rolling 🔁 - Stop when you reach a goal 🎯
- Count rolls and find the winner 🥇
- Put it all in a function 🛠️
You finished Roll the Dice Game AND the whole course! 🎉🎲
Frequently asked questions
Is the “First to Twenty” lesson free?
Yes — the full text of “First to Twenty” is free to read here on the web, and the Coding for Kids course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Coding for Kids course, upgrade to CoddyKit PRO.
What will I learn in “First to Twenty”?
Build the game. You practise Coding for Kids with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Coding for Kids?
No prior experience is required. Coding for Kids on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “First to Twenty” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Coding for Kids lesson?
Yes. Every Coding for Kids lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Rolling One Die
- Rolling Two Dice
- Tracking Dice Points
- First to Twenty