forked from kse-ua/git-playground
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
40 lines (28 loc) · 991 Bytes
/
main.py
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
import words_fetcher
import random
def congratulate_user():
print(f"Congratulations, you won! your words: {guesses}")
def is_game_over():
return guessed == WORDS_TO_WIN or errors == ERRORS_TO_LOSE
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}'")
while not is_game_over():
guess = input("Your next take: ")
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
print(f"Oops :( No such word, you have {ERRORS_TO_LOSE - errors} lives more")