WEBVTT

00:00.000 --> 00:14.000
In this video, we will understand and apply user input handling. Use string formatting to create dynamic stories.

00:14.000 --> 00:29.000
Let's create a simple madlibs game using Python. In this project, you will learn how to take user input, insert it into a story template, and generate personalized stories while practicing loops and string formatting.

00:29.000 --> 00:39.000
Creating a story template. Before we start, we need a story template. Think of it as a fill in the blank worksheet.

00:39.000 --> 00:53.000
Story templates is equal to open brace, fantasy. In a land called Place, there was a adjective, creature, who loved to, verb, adventure.

00:54.000 --> 01:09.000
Deep in the place, a adjective, explore, found, a mysterious object, closed brace. We create a dictionary called story templates. It has two story themes, fantasy, and adventure.

01:09.000 --> 01:16.000
Each theme has a story with placeholders like Place, adjective, where we will insert user words.

01:16.000 --> 01:25.000
Asking for input and choosing a theme. Now, we need to ask the user for input and let them pick a theme. But what if they don't enter anything?

01:25.000 --> 01:44.000
We need to check that too. Deaf get input, prompt. While true, user input is equal to input, prompt.strip. If user input, return user input, else, print. Please enter a valid word.

01:44.000 --> 01:52.000
This function makes sure the user enters a word before moving forward. If they leave it blank, it keeps asking until they type something.

01:52.000 --> 02:04.000
Now, let's start the game and ask for a theme. Deaf main. Print. Welcome to the Simple Mad Libs Story Builder.

02:04.000 --> 02:16.000
While true, print. BackslashN. Choose a theme for your story. For theme and story templates. Print.f. theme.

02:16.000 --> 02:29.000
Theme is equal to get input. Enter your theme.capitalize. If theme not in story templates. Print. Invalid theme. Please choose a valid option.

02:29.000 --> 02:40.000
Continue. We display available themes, fantasy or adventure. The user chooses one. And if they enter something wrong, we ask again.

02:40.000 --> 02:56.000
User input collection. Once the user picks a theme, we ask for words to fill in the blanks. Print.f. BackslashN. You chose the theme. Theme. Let's fill in the blanks.

02:56.000 --> 03:10.000
Place is equal to get input. Enter a place. Adjective is equal to get input. Enter an adjective. If theme is equal to fantasy, creature is equal to get input. Enter a creature.

03:10.000 --> 03:32.000
Verb is equal to get input. Enter a verb. Story is equal to story templates. Theme.Format. Place is equal to place. Adjective is equal to adjective. Creature is equal to creature. Verb is equal to verb. Else. Object underscore is equal to get input. Enter an object.

03:32.000 --> 03:44.000
Story is equal to story templates. Theme.Format. Place is equal to place. Adjective is equal to adjective. Object is equal to object underscore.

03:44.000 --> 03:59.000
Depending on the chosen theme, we ask for different words. We use the format method to insert words into the story. Displaying the story and playing again. Finally, we show the completed story and ask if they want to play again.

03:59.000 --> 04:23.000
Print. BackslashN. Here's your story. Print. Story. Play again is equal to input. BackslashN. Would you like to create another story? Yes. No. .strip.lower. If play again is equal to yes. Print. Thank you for playing. Goodbye.

04:23.000 --> 04:45.000
Great. Men. Save the program with a name like Mad Libs Story Builder. Click the Run button to create your own fun story. Great job. You have built a fun Mad Libs game while learning about user input, loops, and string formatting. Keep experimenting with new templates and have fun coding.

