Lists Review & Radio Communication
Python ·Review: Heads Guess! Game Plan
Let’s review what we built last week! The Heads Guess! game:
- Create a list of words to guess
- Start a 30-second countdown
- When tilted up (logo up): show a random word
- When tilted down (screen down): add a point (correct!)
- When tilted back (screen up): lose a life (pass)
Step 1: Start the Countdown ⏱️
We want 30 seconds to play the game.
game.start_countdown(30000)
Why 30000? Time is in milliseconds! 30 seconds × 1000 = 30,000 milliseconds
Step 2: Create Word List
Let’s make a list of words to guess!
wordList = ["PUPPY", "CLOCK", "NIGHT"]
game.start_countdown(30000)
Try it yourself: Add more words to make the game more fun! Ideas: “DANCE”, “PIZZA”, “OCEAN”, “ROBOT”
Step 3: Get New Word Gesture
When the micro:bit logo points up, we want to show a new word.
def on_logo_up():
# We'll add code here!
input.on_gesture(Gesture.LOGO_UP, on_logo_up)
This is the gesture for “show me the next word!”
Step 4: Pick Random Index
Inside the function, pick a random word from our list:
def on_logo_up():
index = randint(0, len(wordList) - 1)
Why len(wordList) - 1? If we have 3 words, valid indices are 0, 1, 2!
Step 5: Show the Random Word
Now display the word at that random index:
def on_logo_up():
index = randint(0, len(wordList) - 1)
basic.show_string(wordList[index])
The word will scroll across the screen!
Step 6: Correct Guess! ✓
When the player guesses correctly, they tilt screen down.
def on_screen_down():
# Add code here!
input.on_gesture(Gesture.SCREEN_DOWN, on_screen_down)
What should happen when they guess correctly?
Step 7: Add a Point! 🎯
When they guess correctly, give them a point!
def on_screen_down():
game.add_score(1)
The micro:bit will keep track of their score automatically!
Step 8: Pass Gesture
When the player wants to pass (skip a word), they tilt screen up.
def on_screen_up():
# Add code here!
input.on_gesture(Gesture.SCREEN_UP, on_screen_up)
But passing should have a consequence…
Step 9: Lose a Life 💔
If you pass, you lose a life!
def on_screen_up():
game.remove_life(1)
This encourages players to keep trying!
Complete Code! 🎉
wordList = ["PUPPY", "CLOCK", "NIGHT", "DANCE", "PIZZA"]
def on_logo_up():
index = randint(0, len(wordList) - 1)
basic.show_string(wordList[index])
def on_screen_down():
game.add_score(1)
def on_screen_up():
game.remove_life(1)
input.on_gesture(Gesture.LOGO_UP, on_logo_up)
input.on_gesture(Gesture.SCREEN_DOWN, on_screen_down)
input.on_gesture(Gesture.SCREEN_UP, on_screen_up)
game.start_countdown(30000)
Time to Play! 🎮
Download your code to the micro:bit!
How to play:
- Partner up - one guesser, one clue-giver
- Guesser holds micro:bit on forehead
- Tilt logo up to see a new word
- Clue-giver gives hints (no saying the word!)
- Tilt screen down when guessed correctly
- Tilt screen up to pass
- You have 30 seconds - go!
Challenge: More Words! 📝
Add at least 10 more words to your list.
Categories to try:
- Animals
- Foods
- Activities
- School subjects
- TV shows
- Sports
Make the game harder and more fun!
Key Concepts Review ✨
From last week, you learned:
- Lists - Collections that hold multiple items
- Indexing - Accessing items (starts at 0!)
- List length -
len(list)tells you how many items - Random selection -
randint(0, len(list) - 1) - Gestures - Tilting micro:bit to control games
- Game functions -
add_score(),remove_life()
Why Lists Matter 💡
Lists let you:
- Organize related data together
- Easily add or remove items
- Pick random items
- Loop through items (we’ll learn this later!)
- Build more complex programs
They’re one of the most important tools in programming!