-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday7_hangman_game.py
More file actions
42 lines (34 loc) · 1.15 KB
/
day7_hangman_game.py
File metadata and controls
42 lines (34 loc) · 1.15 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
33
34
35
36
37
38
39
40
41
42
import random
lives = 6
game_over = False
correct_letters = []
list_of_words = ["python", "java", "kotlin", "javascript", "ruby", "swift", "go", "rust"]
random_word = random.choice(list_of_words)
print(random_word)
len_of_random_word = len(random_word)
empty_string = "_" * len_of_random_word
print(empty_string)
while not game_over:
print("*************", lives, "/6 LIVES LEFT **********")
guess = input("Guess a letter: ").lower()
if guess in correct_letters:
print("You already guessed" + guess)
display = ""
for letter in random_word:
if letter == guess:
display += letter
correct_letters.append(guess)
elif letter in correct_letters:
display += letter
else:
display += "_"
print(display)
if guess not in random_word:
lives -= 1
print("You guessed" + guess + " and it is not a correct letter")
if lives == 0:
game_over = True
print("***************You lose.******************")
if "_" not in display:
game_over = True
print("************Game Over - You win.************")