1
Hatchling0 / 300 XP
0day streak 0stars
Your Python practice
Mock tests Readiness
More
Guest mode · saved on this device.

Project: Mad Libs

Time to combine everything: input, variables and joining strings.

A Mad Libs game asks for random words and drops them into a story. The fun part is that the player has not seen the story yet.

See it run

pet = "otter"   # in the lesson: pet = input("A pet: ")
food = "kelp"
glued = pet + food
spaced = pet + " " + food
print(glued)
print(spaced)

A Mad Libs sentence is pieces joined with +. Watch what + does and does not add.

Practice project: mad libs

Exercise 1

Ask for an adjective, a noun and a verb (the player types purple, dragon, dance). Store them in adjective, noun and verb, then print exactly:

The purple dragon loves to dance.

Exercise 2

Make a postcard generator. Read traveller, place, then weather from Ivo, Oslo, snowy. Print exactly Ivo says: Oslo is snowy today.

Exercise 3

Create a treasure clue. Read colour, thing, then integer steps from red, gate, 7. Compute return_steps = steps + 2. Print Walk 7 steps to the red gate. and Return in 9 steps. on separate lines.

Free lesson: use the editor to practice it.

Practice

Loading Python…
More
Loading exercise content…
Visualizer Watch your code run line by line

Run your code, then choose Play to follow its execution.

Memory · names → values
Variables appear here as Python creates them.
Output & plots

One-line daily quest