import random
HANGMAN = (
"""
------
| |
|
|
|
|
|
|
|
----------
""",
"""
------
| |
| O
|
|
|
|
|
|
----------
""",
"""
------
| |
| O
| -+-
|
|
|
|
|
----------
""",
"""
------
| |
| O
| /-+-
|
|
|
|
|
----------
""",
"""
------
| |
| O
| /-+-/
|
|
|
|
|
----------
""",
"""
------
| |
| O
| /-+-/
| |
|
|
|
|
----------
""",
"""
------
| |
| O
| /-+-/
| |
| |
| |
| |
|
----------
""",
"""
------
| |
| O
| /-+-/
| |
| |
| | |
| | |
|
----------
""")
WORDS = ("dupa", "myszka", "klawiatura", "monitor", "komputer")
MAX_WRONG = len(HANGMAN)-1
word = random.choice(WORDS)
so_far = "-" * len(word)
used = []
wrong = 0
def ask_letter(question):
guess = input(question).lower()
while guess in used:
guess = input(question).lower()
used.append(guess)
return guess
def check_letter(guess):
if guess in word:
new = ""
for i in range(len(word)):
if guess == word[i]:
new += guess
else:
new += so_far[i]
so_far = new
return so_far
else:
print("\nLitera nie znajduje się w haśle")
wrong += 1
return wrong
def main():
while wrong < MAX_WRONG and so_far != word:
guess = ask_letter("Proszę podać literę")
check_letter(guess)
if wrong == MAX_WRONG:
print("\nZostałeś powieszony")
else:
print("Wygrałeś")
main()
input("\nESC")