-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhangman.py
105 lines (92 loc) · 2.61 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
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import random
def hangg():
word=random.choice(["starwars","batman","avengers","ironman","supernaturals","sunshine","titanic","thor","interstellar"])
valid="abcdefghijklmnopqrstuvwxyz"
turns=10
guessing=""
while len(word)>0:
main=""
for i in word:
if i in guessing:
main = main + i
else:
main = main + "_" + " "
print(main)
guess=input("Make your guess")
if guess in guessing:
print ("Already entered by you....make another guess")
guess=input()
if guess in valid:
guessing=guessing+guess
else:
print("Enter a valid character")
guess=input()
if guess not in word:
turns=turns-1
turnp(turns)
if(turns==0):
break
if main==word:
print("Yes.. the word is %s ",main)
print("You won!")
break
def turnp(n):
print("turns left:",n)
if n==9:
print("_________")
elif n==8:
print("_________")
print(" O ")
elif n==7:
print("_________")
print(" O ")
print(" | ")
elif n==6:
print("_________")
print(" O ")
print(" | ")
print(" / ")
elif n==5:
print("_________")
print(" O ")
print(" | ")
print(" / \ ")
elif n==4:
print("_________")
print(" \O ")
print(" | ")
print(" / \ ")
elif n==3:
print("_________")
print(" \O/ ")
print(" | ")
print(" / \ ")
elif n==2:
print("The man is gonna die! Make wise guess")
print("_________")
print(" \O/| ")
print(" | ")
print(" / \ ")
elif n==1:
print("The rope has been tied!!!")
print("You have last chance")
print("_________")
print(" \O_| ")
print(" |\ ")
print(" / \ ")
elif n==0:
print("Oops! the innocent man died...")
print("_________")
print(" O_| ")
print(" /|\ ")
print(" / \ ")
def hang():
i=input("Do you want to play hangman (y/n) ? ")
if(i=="Y" or i=="y"):
name = input("Who are you??")
print("Welcome to the game ", name)
print("____________________________")
print("You have to guess the word within 10 attempts to save the innocent man from getting hanged")
hangg()
else:
print("okay not playing")