-
Notifications
You must be signed in to change notification settings - Fork 204
Expand file tree
/
Copy pathHangman.py
More file actions
65 lines (55 loc) · 1.21 KB
/
Hangman.py
File metadata and controls
65 lines (55 loc) · 1.21 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
# Classic Game of Hangman
# Created by Santosh Vasisht
import random
# Initialization
fruit_list = [
"apple",
"banana",
"orange",
"mango",
"strawberry",
"watermelon",
"kiwi",
"peach",
"pear",
"papaya",
"grapes",
"pineapple",
"guava",
"blueberry",
"blackberry",
"raspberry",
"apricot",
]
choice = "Y"
# Game Start
while choice == "Y":
# Setup
fruit = random.choice(fruit_list)
lives = 5
temp = []
word = []
for i in fruit:
word.append(i)
temp.append("_")
print("\n\tHANGMAN!")
# Gameplay
while "_" in temp and lives != 0:
print() # newline
for i in temp:
print(i, end=" ")
print("\t Lives:", lives, "\n")
l = input("Guess a letter: ").lower()
if l in word:
for i in range(0, len(word)):
if word[i] == l:
temp[i] = l
else:
lives -= 1
# Game End
if lives == 0:
print("\nGAME OVER!")
else:
print("\nYOU WIN!!!")
print("The word was", fruit.upper())
choice = input("\nPlay Again?(y/n) ").upper()