Today This Free Friday I am working on a project on YouTube a Madlibs Generator
with open("story.txt" , "r") as f:
story = f.read()
words = []
start_of_word = -1
target_start = "<"
target_end = ">"
for i, char in enumerate(story):
if char == target_start:
start_of_word = i
if char == target_end and start_of_word != -1:
word = story[start_of_word: i + 1]
words.append(word)
start_of_word = -1
- This part of the code is to tell the user to choose a word of their choose for it to generators a story
answers = {}
for word in words:
answer = input("Enter a word for " + word + ": ")
answers[word] = answer
for word in words:
story.replace(word, answers[word])
print(story)
- This part of the code is generators words from the user to make story at of it