-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path01-wisielec.py
More file actions
51 lines (37 loc) · 1016 Bytes
/
01-wisielec.py
File metadata and controls
51 lines (37 loc) · 1016 Bytes
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
import sys
no_of_tries = 5
word = "kamila"
used_letters = []
user_word = []
def find_indexes(word, letter):
indexes = []
for index, letter_in_word in enumerate(word):
if letter == letter_in_word:
indexes.append(index)
return indexes
def show_state_of_game():
print()
print(user_word)
print("Pozostało prób:", no_of_tries)
print("Użyte litery:", used_letters)
print()
###
for _ in word:
user_word.append("_")
while True:
letter = input("Podaj literę: ")
used_letters.append(letter)
found_indexes = find_indexes(word, letter)
if len(found_indexes) == 0:
print("Nie ma takiej litery.")
no_of_tries -= 1
if no_of_tries == 0:
print("Koniec gry :(")
sys.exit(0)
else:
for index in found_indexes:
user_word[index] = letter
if "".join(user_word) == word:
print("Brawo, to jest to słowo!")
sys.exit(0)
show_state_of_game()