Skip to content

Commit 9b19af2

Browse files
committed
Fifth project
1 parent 216dcdb commit 9b19af2

File tree

3 files changed

+44
-14
lines changed

3 files changed

+44
-14
lines changed

.idea/workspace.xml

Lines changed: 15 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

python_story.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
with open('story.txt', 'r') as f:
2+
story = f.read()
3+
4+
words = set()
5+
start_of_word = -1
6+
7+
target_start = '<'
8+
target_end = '>'
9+
10+
for i, char in enumerate(story):
11+
if char == target_start:
12+
start_of_word = i
13+
14+
if char == target_end and start_of_word != 1:
15+
word = story[start_of_word: i + 1]
16+
words.add(word)
17+
start_of_word = -1
18+
19+
answers = {}
20+
21+
for word in words:
22+
answer = input('Enter a word for '+ word + ':')
23+
answers[word] = answer
24+
25+
for word in words:
26+
story = story.replace(word, answers[word])
27+
28+
print(story)
29+

story.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)