This script reads a text file (story.txt
) and identifies placeholders wrapped in <
and >
. It prompts the user to input custom words to replace these placeholders, generating a personalized story.
- Reads a text file containing a story.
- Detects placeholders wrapped in
<
and>
(e.g.,<name>
). - Prompts the user to input replacements for each placeholder.
- Outputs the modified story with the user-provided words.
-
Create a
story.txt
file in the same directory as the script. The file should contain a story with placeholders wrapped in<
and>
.
Example:Once upon a time, there was a <character> who lived in a <place>.
-
Run the script:
python storyGenerator.py
-
Enter inputs when prompted:
enter a word for <character>: hero enter a word for <place>: castle
-
View the customized story printed in the console.
Example Output:
Once upon a time, there was a hero who lived in a castle.
project/
│
├── storyGenerator.py # The main Python script
├── story.txt # Text file containing the story
-
Read the Story File:
- Opens and reads
story.txt
.
- Opens and reads
-
Identify Placeholders:
- Searches for text enclosed in
<
and>
. - Stores these placeholders in a
set
to ensure unique entries.
- Searches for text enclosed in
-
Collect User Input:
- Prompts the user for a replacement word for each placeholder.
-
Replace Placeholders:
- Replaces the placeholders in the story with user-provided inputs.
-
Display the Final Story:
- Prints the modified story with the user's custom words.
- Python 3.x