Python (Fall 2026) Module 2-12: A2 Explanation (using Pycharm)
Overview
Bill Moseley explains the Module 2 Mad Libs assignment: collect four to five words with Python `input()`, insert them into a story with an f-string, and print the result. Using PyCharm, he demonstrates triple-quoted multiline strings, curly-brace placeholders, and input prompts, while noting that students may use the provided template, write their own story, or ask AI to generate one.
Key takeaways
- A basic Mad Libs program needs four to five `input()` calls, one variable per response, placeholders in the story, and a final print statement.
- Python triple-quoted strings preserve line breaks and spacing, making them useful for formatting story text without manually joining lines.
- An f-string uses curly braces around variable names, such as `{strAdj}`; square brackets do not substitute variable values.
- The string passed to `input()` is the instruction shown to the user, while the value the user types is what gets stored in the variable.
- Students may use AI-generated text, their own story, or the A2 template in Canvas, so the required programming technique matters more than the story's source.
Chapters
- The assignment asks for four to five user-supplied words, such as an adjective, animal, silly word, profession, and place.
- Students can use the supplied sample story, create original text, or ask AI to generate a funny story with five blanks.
- The goal is to store each response in a variable, substitute the words into the story, and print the completed text.
- Bill Moseley uses three quote marks at the start and end of a string so the story can preserve line breaks and whitespace.
- The story becomes an f-string by adding `f` before its opening quotes, then replacing square-bracket placeholders with curly-brace expressions such as `{strAdj}` and `{strAnimal}`.
- PyCharm marks placeholders red until their corresponding variables are defined, so each variable must be assigned before the story is printed.
- Each word is collected with `input()` and a prompt such as “Give me an adjective:”; calling `.strip()` removes surrounding whitespace.
- The prompt text tells users what kind of word to enter, while the user's answer is captured by `input()` and stored in the variable.
- A sample run uses “green,” “fox,” “Shoot,” “lawyer,” and “Bakersfield” to produce a customized story.
- The optional A2 template is in Canvas under Module Two, then Starter Files for Module Two; the assignment requires four to five substitutions and a printed result.
Transcript excerpt
0:02 So that leads me to our assignment for this module. This assignment is called Mad Libs. And maybe some of you have heard of Mad Libs. This is. It's kind of old at this point, but Mad Libs used to be a thing that you used to be able to buy, these little books, and they were full of pages, and each page had a little story in it. And that story had little blanks in there with like a word under it, like adjective or an invention or food or a noun or a verb. And the idea is that they're a fun way for kids to learn like the parts of speech, like what's the difference between a noun and a verb and an adjective, while they write these little stories. Now, kids being kids, often write really stupid things in there like poop and fart and, like,
0:54 you know, because that's what kids do. But they're still learning parts of speech in a fun way. So in this assignment, I'm giving you some starter text. In fact, this exact text as a sample story, which you can use. You can also make up your own Mad Libs text if you want. A third option is to ask AI to create a Mad Libs for you. Now, what I'm asking you to do is to get user input on four to five different words. So you would, for example, ask them, "Give me a noun." You put that into a variable. Give me a verb. You put that into a variable. So you're doing that four to five times,
1:44 and then you're using either string format or an f-string to insert those words into the Mad Libs text and print it out. It's pretty simple, but let me walk you through how I'm going to do
This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.
In this course
Related notes
Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Bill Moseley, Ph.D. - Computer Science Educator.