-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhangman.py
84 lines (76 loc) · 1.18 KB
/
hangman.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'rainer'
"""
Hangman
"""
HANGMANPICS = ['''
+---+
| |
|
|
|
|
=========''', '''
+---+
| |
O |
|
|
|
=========''', '''
+---+
| |
O |
| |
|
|
=========''', '''
+---+
| |
O |
/| |
|
|
=========''', '''
+---+
| |
O |
/|\ |
|
|
=========''', '''
+---+
| |
O |
/|\ |
/ |
|
=========''', '''
+---+
| |
O |
/|\ |
/ \ |
|
=========''']
iterator = iter(HANGMANPICS)
from getpass import getpass
geheimnis = getpass("dein Geheimnis\n")
charaters_found = []
def print_guess(geheimnis, values):
return "_".join(x for x in geheimnis if x in values)
while True:
guess_char = input("Dein Vorschlag?\n")
if guess_char not in geheimnis:
try:
print(next(iterator))
except StopIteration:
print("Game Over")
break
else:
charaters_found.append(guess_char)
if len(set(charaters_found)) == len(set(geheimnis)):
print("Gewonnen :)")
break
print(print_guess(geheimnis, charaters_found))