micro:bit Wordle game

screenshot of micro:bit Wordle game

I made a Wordle-like game in Python for the BBC micro:bit.

The code is pretty compact and easy to understand, so I think getting students to create their own version of this popular game or pick apart this one would make a nice activity. There are plenty of opportunities to improve it.

You could use it to:

  • teach some Python
  • learn about functions
  • learn about using global variables in functions
  • learn about slicing strings
  • use imports – I hide the word list in an import
  • experiment with the serial console in the new alpha micro:bit Python editor

You’ll need a micro:bit and a Chrome or Edge browser as it uses webUSB – you interact with the micro:bit using your computer’s keyboard and screen.

You get 5 guesses. It shows your progress on the micro:bit’s LED display: a bright LED means the right letter in the right place, a dim LED means the right letter in the wrong place.

It also prints out your progress in the serial console. Capital letters are in the right place, lower case in the wrong place: So


means the word ends in T and has an ‘a’ in 1st, 2nd or 4th place.

You can download a hex file to flash direct onto a micro:bit or drag and drop onto the Python editor, plus the raw Python files over on GitHub: https://github.com/blogmywiki/wordobit.

You’ll probably want to add more words to words.py. You could also improve the program in lots of ways, for example add some simple encryption like ROT13 to the word list or add more word checking.

I also made a video to explain how it works and how to play it:

main.py code

from microbit import *
import random
import music
from words import wordlist

def newWord():
    print('New game!')
    global word
    global turn
    word = random.choice(wordlist)
    turn = 0


while True:
    if turn > 4:
        print('You lose. Your score is X/5. The word was ' + word)
    guess = input('What is your guess? ')
    if len(guess) != 5:
        print('Not a 5 letter word!')
        progress = ''
        for a in range(5):
            if guess[a] in word:
                if guess[a] == word[a]:
                    progress = progress + guess[a].upper()
                    progress = progress + guess[a].lower()
                progress = progress + '-'
        turn += 1
        if guess == word:
            print('Congratulations! Your score is ' + str(turn) + '/5')

words.py code

# List of 5 letter words hidden from main Python program view
wordlist = ['heart', 'aloft', 'float', 'banjo', 'scoop']
This entry was posted in Uncategorized and tagged , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>