Project: Mad Libs
Project: Mad Libs
- In this project you build a small story machine.
- It asks for a few words, then puts them into a story.
- You use what you know:
input(), joining strings with+, and string methods.
What you will build
Mia
cat
pizza
The story of Mia
================
Mia has a pet CAT.
It eats pizza every day.
- The first three lines are what the user types. The rest is the story.

Step 1: collect the words
- Each
input()reads one line. Store each word in its own variable. - Join the words with
+, and put the spaces inside the quotes.
Step 2: change a word
.upper()gives a CAPITAL copy:"cat".upper()is"CAT".- Each
printadds one line to the story.
Step 3: a title with a line under it
len(text)counts the characters in a string."=" * 5repeats a string five times:=====.- So
"=" * len(title)draws a line exactly as long as the title.
title = "Hello"
print(title)
print("=" * len(title))
Now build it
- Three steps. Each task starts with your code from the step before.
- Press Run and type the words yourself, then press Check answer.
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Step 1: read a ชื่อ, then an animal, each with input(). Print one sentence. For the inputs Mia และ cat, print Mia has a pet cat.
คลิก Run เพื่อดูผลลัพธ์ที่นี่
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Step 2: also read a อาหาร. Print two lines: the first sentence with the animal in CAPITALS, then It eats + the food + every day. สนับสนุน Mia, cat และ pizza: Mia has a pet CAT. และ It eats pizza every day.
คลิก Run เพื่อดูผลลัพธ์ที่นี่
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Step 3: start the story with a title, The story of + the name, and underline it with = signs exactly as long as the title (use len). For Mia the first two lines are The story of Mia และ ================.
คลิก Run เพื่อดูผลลัพธ์ที่นี่