forked from animeshsrivastava24/PythonScriptsForBeginners
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhangman.py
More file actions
35 lines (32 loc) · 884 Bytes
/
hangman.py
File metadata and controls
35 lines (32 loc) · 884 Bytes
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
import time
import random
name = input("What is your name? ")
print ("Hello, " + name, "Time to play hangman!")
print (" ")
time.sleep(1)
print ("Start guessing...")
time.sleep(0.5)
words=["secret","robust","elixer","random","sponsor"]
word=random.choice(words)
guesses = ''
turns = 10
while turns > 0:
failed = 0
for char in word:
if char in guesses:
print (char,)
else:
print ("_",)
failed += 1
if failed == 0:
print ("You won")
break
print
guess = input("guess a character:")
guesses += guess
if guess not in word:
turns -= 1
print ("Wrong")
print ("You have", + turns, 'more guesses')
if turns == 0:
print ("You Lose")