Hello all.
So I am trying to write a program that will read in a text file, then it will scan the file for prompts, such as %, %[noise], etc. Then from what prompts are within that file, the program will ask the user what word they would like to replace the prompt with.
Example stories:
%[adjective] MacDonald had a %[business], E-I-E-I-O.
And on that %[business] he had a %[animal], E-I-E-I-O.
With a %[noise] %[noise] here, and a %[noise] %[noise] there,
here a %[noise], there a %[noise], everywhere a %[noise] %[noise],
%[adjective] MacDonald had a %[business], E-I-E-I-O.
So it would find the %[adjective], %[business], %[animal], %[noise]. Then ask, what adjective, business, animal and noise the user would like to use.
myFile=raw_input("What is the file name?: ")
myFile=open(myFile)
myFile=myFile.read()
myString1 = raw_input("Type an adjective: ")
myString2 = raw_input("Type a business: ")
myString3 = raw_input("Type a animal: ")
myString4 = raw_input("Type a noise: ")
Punct=["[","]","%"]
s = myFile
np=s
for p in Punct:
np=np.replace(p,"")
np = np.replace("adjective", myString1)
np = np.replace("business", myString2)
np = np.replace("animal", myString3)
np = np.replace("noise", myString4)
print np
That is my code for this story, but I don't know how to write the program to scan for the tags and prompt the user based on the tags within the text file. It needs to work with other stories like the following.
%[girls_name] had a little %[animal],
little %[animal], little %[animal],
%[girls_name] had a little %[animal]
its fleece was % as snow.
It followed her to %[place] one day,
%[place] one day, %[place] one day,
it made the children %[verb] and play
to see a %[animal] at %[place].
So ask for girls_name, animal, color, place and verb.
Any tips or points into the right direction would help a lot. I am sorta new to python, I feel stupid. But would love the feedback, thanks!