forked from unton3ton/Scaffolds
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscaffold2.py
53 lines (48 loc) · 1.54 KB
/
scaffold2.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
#!/usr/bin/python2
# -*- encoding: utf-8 -*-
import random
import urllib2
word_site = "http://svnweb.freebsd.org/csrg/share/dict/words?view=co&content-type=text/plain"
response = urllib2.urlopen(word_site)
txt = response.read()
WORDS = txt.splitlines()
word_list = len(WORDS)
random_number = random.randint(0, word_list)
def hangman(word):
wrong = 0
stages = ["",
"________ ",
"| ",
"| | ",
"| 0 ",
"| /|\ ",
"| / \ ",
"| "
]
rletters = list(word)
board = ["__"] * len(word)
win = False
print "Добро пожаловать на казнь английских слов!"
while wrong < len(stages) - 1:
print("\n")
msg = "Введите букву: "
char = raw_input(msg)
if char in rletters:
cind = rletters.index(char)
board[cind] = char
rletters[cind] = '$'
else:
wrong += 1
print " ".join(board)
e = wrong + 1
print "\n".join(stages[0: e])
if "__" not in board:
print "Вы выиграли! Было загадано слово: "
print " ".join(board)
win = True
break
if not win:
print "\n".join(stages[0: wrong])
print "Вы проиграли! Было загадано слово: {}.".format(word)
#print WORDS[random_number]
hangman(WORDS[random_number])