Skip to content

Instantly share code, notes, and snippets.

@camilajenny
Created April 16, 2026 20:27
Show Gist options
  • Select an option

  • Save camilajenny/941cd1f786460689f76ce8efaee3b2e3 to your computer and use it in GitHub Desktop.

Select an option

Save camilajenny/941cd1f786460689f76ce8efaee3b2e3 to your computer and use it in GitHub Desktop.
Spelling exercises in English
import random
VOWELS = "aeiou"
CONSONANTS = "bcdfghjklmnpqrstvwxyz"
# Confusable letter pairs (trap mode)
TRAPS = [
("b", "p"),
("m", "n"),
("d", "t"),
("g", "k"),
("i", "e"),
("f", "v"),
("s", "z"),
("j", "g")
]
def generate_word(min_len=4, max_len=7, trap_mode=False, trap_chance=0.3):
length = random.randint(min_len, max_len)
word = []
is_vowel = random.choice([True, False])
trap_inserted = False
for i in range(length):
# Ensure at least one trap if trap_mode is on
force_trap = trap_mode and not trap_inserted and i == length - 1
if trap_mode and (random.random() < trap_chance or force_trap):
pair = random.choice(TRAPS)
letter = random.choice(pair)
trap_inserted = True
else:
if is_vowel:
letter = random.choice(VOWELS)
else:
letter = random.choice(CONSONANTS)
is_vowel = not is_vowel
word.append(letter)
return "".join(word)
def generate_words(n=2, trap_mode=False):
return [generate_word(trap_mode=trap_mode) for _ in range(n)]
def spell(word, spaced=True):
letters = list(word.upper())
return (" - " if spaced else " ").join(letters)
def make_script(words, max_chars=500):
parts = ["Listen carefully. Write what you hear.\n"]
for i, w in enumerate(words):
parts += [
spell(w, True),
"Pause.",
spell(w, False),
"Pause."
]
if i < len(words) - 1:
parts += ["Next word."]
text = "\n\n".join(parts)
return text[:max_chars]
# 🔥 Run it
words = generate_words(2, trap_mode=True)
# print(words) # see generated words
print(make_script(words))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment