71.0k views
0 votes
Write a program that plays a game where a player is asked to fill in various words of a mostly complete story without being able to see the rest. Then the user is shown his/her story, which is often funny. The input for your program is a set of story files, each of which contains "placeholder" tokens surrounded by < and >, such as:

One of the most characters in fiction is named
"Tarzan of the ." Tarzan was raised by a/an and lives in the jungle in the heart of darkest .
The user is prompted to fill in each of the placeholders in the story, and then a resulting output file is created with
the placeholders filled in. For example:
Input file name? story1.txt
Please enter an adjective: silly
Please enter a plural noun: socks
Please enter a noun: tree
Please enter an adjective: tiny
Please enter a place: Canada
The resulting output story would be:
One of the most silly characters in fiction is named
"Tarzan of the socks." Tarzan was raised by a/an

1 Answer

4 votes

Final answer:

To create a program that plays a story-filling game, you can use input prompts and string manipulation to fill in the placeholders in a given story. Here is a simplified example of how the program can be implemented.

Step-by-step explanation:

How to Create a Story-Filling Program
To create a program that plays the described story-filling game, you can use a combination of input prompts and string manipulation. Here is a simplified example:

  1. Read the input file line by line.
  2. Use a regular expression to identify and extract the 'placeholder' tokens surrounded by < and >.
  3. Prompt the user to enter the corresponding word for each placeholder.
  4. Replace each placeholder token in the line with the user's input word.
  5. Write the updated line to an output file.

You can repeat this process for each line in the input file to create the final output file with the placeholders filled in. This program can be expanded upon to handle multiple input files, error handling, and other features.

User Raginmari
by
8.0k points

No related questions found