-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhangman6.py
More file actions
32 lines (32 loc) · 1.06 KB
/
Copy pathhangman6.py
File metadata and controls
32 lines (32 loc) · 1.06 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
#python program 6(hangman)
import time
import random
name = input("What is your name? ")
print ("Hello, ", name, "! Time to play hangman!")
time.sleep(1)
print ("Start guessing...\n")
time.sleep(0.5)
## A List Of Secret Words
words = ['apple','atmosphere','air','ant','ball','balloon','basket','blanket','black','bulb','chair','choir','python','programming','treasure','creative','medium','horror']
word = random.choice(words)
guesses = ''
turns = 5
while turns > 0:
failed = 0
for char in word:
if char in guesses:
print (char,end="")
else:
print ("_",end=""),
failed += 1
if failed == 0:
print ("\nYou won")
break
guess = input("\nguess a character:")
guesses += guess
if guess not in word:
turns -= 1
print('''\nWrong''')
print("\nYou have", + turns, 'more guesses')
if turns == 0:
print ("\nYou Lose")