Press ▶ Run to see what your program does.
Lesson 31: Project: Mad Libs
Level 4, Python First Steps. Build a silly story machine with input and f-strings. The new word: f-string. It follows lesson 30, Error detective. Next comes lesson 32, Practice: the snack shop.
What the lesson explains
The story machine. Ask for words, then fill them into a silly story.
f-strings fill themselves in. An f before the quotes; names in { } become their values. On the card: print(f"A {animal} ate {food}!")
What you do first
One blank. Ask a colour and use it in a sentence. The editor opens with: colour = input("A colour? "). One way to write it: colour = input("A colour? ") / print(f"The sky turned {colour}!"). Answer its question with green. It prints: A colour? green / The sky turned green!.
The code on the screen
f-strings fill themselves in. The editor shows 3 lines: animal = "dragon" / food = "pizza" / print(f"A {animal} ate {food}!"). Run it, and it prints "A dragon ate pizza!".
What you practise
Try it, "One blank": Ask a colour and use it in a sentence. The editor opens with: colour = input("A colour? "). One way to write it: colour = input("A colour? ") / print(f"The sky turned {colour}!"). Answer its question with green. It prints: A colour? green / The sky turned green!.
Project, "Your Mad Libs": Build a story machine. One way to write it: animal = input("An animal? ") / food = input("A food? ") / place = input("A place? ") / print(f"One day a {animal} ate {food} in {place}!"). Answer its questions with dragon, pizza, the moon. It prints: An animal? dragon / A food? pizza / A place? the moon / One day a dragon ate pizza in the moon!.
What PlayBuddy and PlayType say
PlayBuddy: "Project time! Let’s build a silly story machine."
PlayType: "Put an f before the quotes. Then the names in curly brackets fill themselves in."
Help in every lesson
Everything happens on a pretend computer in your browser, so nothing touches your real files. PlayBuddy and PlayType stand beside the board, cheer you on and say when it is your turn.
A green ring shows where to click the first time. After that you do it on your own, and if you slip twice the ring comes back.
Stars
The lesson has 2 things to do. Up to one slip in ten gives three stars, up to one in four gives two, and finishing always gives at least one. Stars and progress are saved in this browser only; there is no account.
About DayOneCode
DayOneCode is an independent learning site, not affiliated with or endorsed by Anthropic. Claude and Claude Code are trademarks of Anthropic.