forked from kse-ua/git-playground
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
64 lines (50 loc) · 1.69 KB
/
main.py
File metadata and controls
64 lines (50 loc) · 1.69 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import words_fetcher
import random
def congratulate_user():
print("=============================")
print("= Congratulations! You won! =")
print("=============================")
print(f"Your words: {guesses}")
def is_game_over():
return guessed == WORDS_TO_WIN or errors == ERRORS_TO_LOSE
def guess_is_valid(candidate):
for letter in candidate:
if letter not in word:
print(f"You can not use letter {letter}")
return False
count = word.count(letter)
if count < candidate.count(letter):
print(f"You can use letter {letter} only {count} times")
return False
return True
guessed = 0
errors = 0
guesses = []
WORDS_TO_WIN = 5
ERRORS_TO_LOSE = 3
words = words_fetcher.fetch_words(min_letters=9, max_letters=9)
full_list = words_fetcher.fetch_words(min_letters=3, max_letters=9)
word = words[random.randrange(0, len(words))]
print(f"Can you make up {WORDS_TO_WIN} words from letters in word provided by me?")
print(f"Your word is '{word}'")
already=[]
while not is_game_over():
guess = input("Your next take: ")
while guess in already:
guess = input("This word already entered, try another: ")
already.append(guess)
if not guess_is_valid(guess):
continue
if guess in full_list:
guessed += 1
guesses.append(guess)
if guessed == WORDS_TO_WIN:
congratulate_user()
exit()
print(f"That's right! {WORDS_TO_WIN - guessed} to go")
else:
errors += 1
if errors==3:
print("Sorry you have no lives, you lost")
else:
print(f"Oops :( No such word, you have {ERRORS_TO_LOSE - errors} lives more")