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.
اضغط تشغيل لرؤية المخرجات هنا.
الصعوبة 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.
اضغط تشغيل لرؤية المخرجات هنا.
الصعوبة 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 و ================.
اضغط تشغيل لرؤية المخرجات هنا.