The Mad Libs Generator is a fun Python project that allows users to create personalized stories by filling in placeholders with their own words. The script reads a template story with placeholders from a file and prompts the user for inputs to replace these placeholders, resulting in a unique story each time.
Features
Requirements
Installation
Usage
Example Outputs
How It Works
Customization
Contributing
License
- Reads story templates with placeholders from a file.
- Prompts users for various words to fill in the placeholders.
- Replaces placeholders with user inputs to create a customized story.
- Supports a variety of placeholder types such as , , , etc.
- Outputs the final story with the user's inputs.
- Python 3.x
- A text file containing the story template (e.g.,
story.txt
)
- Clone the Repository:
git clone https://github.com/AmruthGowda91200/mad-libs-generator.git
-
Navigate to the Project Directory:
cd mad-libs-generator
-
Ensure Python 3.x is Installed:
python3 --version
- Create a Story Template:
- Create a file named story.txt in the project directory.
- Add a story with placeholders in the following format:
In the land of <place>, a <adjective> <noun> named <name> decided to explore the <adjective> <fantasy_place>. With a <adjective> <object> and a <adjective> <noun>, <name> ventured into the <adjective> forest.
- Run the Script:
python3 madlibs_generator.py
- Follow the Prompts:
- The script will prompt you to enter words for each placeholder.
- Type in your responses and press Enter.
- View the Customized Story:
- After entering all required words, the script will display the completed story.
Example Command:
python3 madlibs_generator.py
Example Prompt:
Enter a word for <place>: Wonderland
Enter a word for <adjective>: magical
Enter a word for <noun>: explorer
Enter a word for <name>: Alice
...
Example Story Output:
In the land of Wonderland, a magical explorer named Alice decided to explore the magical Enchanted Forest. With a magical map and a magical backpack, Alice ventured into the magical forest.
...
The script reads the content of story.txt
, identifies placeholders within <
and >
, prompts the user for words corresponding to these placeholders, and replaces them in the story to generate a customized output. Here’s a step-by-step breakdown:
- Reading the Story:
with open("story.txt", "r") as f:
story = f.read()
- Finding Placeholders:
- It scans the story for words within < and >.
- Extracts and stores unique placeholders in a set.
- Prompting User:
- Asks the user to input words for each placeholder.
- Stores these inputs in a dictionary.
- Replacing Placeholders:
- Replaces each placeholder in the story with the corresponding user input.
- Outputs the final customized story.
You can customize the Mad Libs generator by:
- Changing the Story Template: Edit
story.txt
with different placeholders and story content. - Adding More Placeholders: Include a variety of placeholders such as
<verb>
,<color>
, etc. - Modifying the Script: Adjust the code to handle new types of placeholders or additional features.
Contributions are welcome! To contribute:
- Fork the repository.
- Create a new branch (git checkout -b feature-branch).
- Make your changes and commit (git commit -m 'Add feature').
- Push to the branch (git push origin feature-branch).
- Open a Pull Request.
This project is licensed under the MIT License. See the LICENSE
file for more details.