forked from Aayush-hub/Basic-Python-Projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHANGMAN.py
More file actions
68 lines (66 loc) · 2.32 KB
/
Copy pathHANGMAN.py
File metadata and controls
68 lines (66 loc) · 2.32 KB
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
import random
print("H A N G M A N")
while True:
gameStart = input('Type "play" to play the game, "exit" to quit: ')
if gameStart == "play":
print("")
wordList = ['python', 'java', 'kotlin', 'javascript','rainbow', 'computer', 'science', 'programming',
'python', 'mathematics', 'player', 'condition',
'reverse', 'water', 'board', 'geeks']
guess = random.choice(wordList)
dashStr = "-" * len(guess)
print(dashStr)
guessedList = []
lives = 8
while lives > 0:
word = input("Input a letter: ")
if len(word) > 1 or len(word) == 0:
print("You should input a single letter")
elif word.islower():
pass
else:
print("It is not an ASCII lowercase letter")
if word in guessedList:
print("You already typed this letter")
print("")
print(dashStr)
continue
else:
guessedList.append(word)
if lives == 0:
print("You are hanged!")
print("")
break
if word in guess:
for j in range(len(guess)):
if guess[j] == word:
dashStr = dashStr[:j] + word + dashStr[j+1:]
if dashStr == guess:
pass
else:
print("")
print(dashStr)
if dashStr == guess:
print("You guessed the word " + dashStr + "!")
print("You survived!")
print("")
break
else:
if len(word) > 1 or not word.islower():
pass
elif word in guessedList and word in guess:
pass
else:
lives -= 1
print("No such letter in the word")
if lives == 0:
pass
else:
print("")
print(dashStr)
if lives == 0:
print("You are hanged!")
print("")
break
else:
break