-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhangman.py
41 lines (41 loc) · 1.07 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
# Hangman Game by Bad McProgammer!
import random
ws = open('word-list.txt')
index = 0
picked = random.randint(0, 25)
for w in ws:
if index == picked:
pick = w
index = index+1
import sys
guessed =[]
word=pick[:-1]
solve = "?" * len(word)
lives = 9
while solve != word:
for index in range(len(word)):
print(solve[index],end="")
print(" ",end="")
print()
print('lives =', end='')
print(lives)
print('please guess')
guess =input().lower()
if guess in guessed:
print('you guessed that already')
elif (guess in word) == False:
print('that\'s not in the word')
lives = lives - 1
else:
print('you got a letter')
for index in range(len(word)):
if word[index] == guess:
solve = solve[0:index] + guess + solve[index+1:]
guessed = guessed + [guess]
if lives < 0:
print('you died, sorry!')
print('The correct word was: ',word)
break
print('you solved the hangman game')
print('The correct word was: ',word)
print('run again to play again')