-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhangman.py
52 lines (40 loc) · 1.36 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
import random
words = ("python", "hangman", "xylophone", "watch", "king", "dog", "animal", "anomaly", "hospital", "exit", "entrance", "jeep", "number", "airplane", "crossing", "tattoo")
lives = None
game_won = False
print("WELCOME TO HANGMAN!!!")
print("You have three lives!")
print("Choose wisely!")
play = input("would you like to play? (y/n) ")
def play_game(lives):
mys_word = random.choice(words)
mys_letters = list(mys_word)
guess_letters = []
game_won = False
print(mys_word)
while game_won == False:
guess = input("what is your guess? ")
if guess in mys_letters:
print(f"Good job! {guess} is in the word!")
guess_letters.append(guess)
print(guess_letters)
elif guess == mys_word:
print("YOU WON! congratulations!!!")
game_won = True
else:
print(f"{guess} is not in the word! You lose a life.")
lives -= 1
if lives == 0:
print("Game Over! You Lose!!")
break
if play == "y":
play_game(5)
else:
print("Thanks for stopping by!")
play_again = input("Would you like to play again? (y/n) ")
while play_again != "n":
play_game(5)
play_again = input("Would you like to play again? (y/n)")
if play_again == "n":
print("Thanks for playing!")
break