-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwords.py
More file actions
34 lines (30 loc) · 1.27 KB
/
Copy pathwords.py
File metadata and controls
34 lines (30 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import random
with open("dict.txt", "r", encoding="utf-8") as f:
words = f.read().split("\n")
bot = input("Play with a bot (Y/n)? ").lower() == "y"
print("Type \"exit\" to exit.")
lastword = None
while True:
word = input("Your word: ").lower()
while lastword is not None and lastword[-1] != word[0] or word not in words:
if word == "exit":
break
if lastword is not None and lastword[-1] != word[0]:
print("The word you typed isn't correct: it doesn't start with the last word's last letter "
f"({lastword[-1]})")
if word not in words:
print("The word you typed isn't correct: it isn't a valid word or it was already used")
word = input("Your word: ").lower()
if word == "exit":
break
words.pop(words.index(word))
lastword = word.replace("ь", "").replace("ъ", "").replace("ы", "").replace("ё", "е")
if bot:
choices = [i for i in words if i[0] == lastword[-1]]
if len(choices) == 0:
print("You... won?")
break
choice = random.choice(choices)
print(f"Bot's choice: {choice}")
words.pop(words.index(choice))
lastword = choice.replace("ь", "").replace("ъ", "").replace("ы", "").replace("ё", "е")