-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhangman.py
91 lines (39 loc) · 1.92 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
import random
name = input("What is your name ? --->> ")
print("\n")
print("It's time to play Hangman "+name)
print("Good Luck\n")
words = ['program', 'trees', 'computer', 'python', 'java', 'syntax', # Insert n number of words here
'house', 'linux', 'system', 'science', 'code', 'network', 'planet']
word = random.choice(words)
# we will you use while loop for the condition till the turns are 0
def game():
print("-------------------------------START----------------------------\n")
print("Start guessing the characters\n")
noofguesses = ''
turns = 13 #these are the no of chances the player will get, you can add yours
while turns > 0:
guess = input("Guess a character ---> ")
print("\n")
noofguesses += guess
failed = 0
for char in word:
if char in noofguesses:
print(char)
else:
print("_")
failed += 1
if failed == 0:
print("You have won the game ")
print("The Word Is -----> ", word)
exit()
if guess not in word :
turns -= 1
print("Wrong Guess :( ")
print("\n")
print("You have ",+turns,"chances left")
print("\n")
if turns == 0:
print("You have lost")
print("The correct word was ----> ",word)
game()