-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHangman
43 lines (35 loc) · 932 Bytes
/
Hangman
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
from random import choice
alph = 'abcdefghijklmnopqrstuvwxyz'
word = choice(['world', 'banana', 'pineapple', 'crowdfunding'])
letters = []
attempts = 5
while True:
letter = raw_input('Enter letter: ')
if letter in letters:
print 'This letter was entered before'
continue
letters.append(letter)
if len([c for c in letters if c in set(word)]) == len(set(word)):
print 'Yep, the word was: %s' % word
break
if letter in word:
for c in word:
if c in letters:
print c,
else:
print '_',
print
else:
attempts -= 1
if attempts == 0:
print 'Sry, u loose'
break
else:
print 'Nope, try another letter'
print 'Unused letters: ',
for c in alph:
if c not in letters:
print c,
else:
print '*',
print