-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
34 lines (33 loc) · 1.11 KB
/
main.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
import random
import os
from hangman_art import stages,logo
from hangman_words import word_list
print (f"{logo}\n\n")
chosen_word = random.choice(word_list)
display = []
for letter in chosen_word:
display.append("_")
lives = 6 #Number of chances available for the user.
guessed_letters = []
while "_" in display and lives !=0:
print(f"{' '.join(display)}\n")
print(stages[lives])
guess = input("Guess a letter: ").lower()
position = 0
os.system('cls' if os.name == 'nt' else 'clear')
if guess not in guessed_letters:
if guess in chosen_word:
for letter in chosen_word:
if letter == guess:
display[position] = letter
position += 1
else:
lives -= 1
print(f"Your guess {guess} is not in the word. You lose a life.")
else:
print(f"You already have guessed the letter {guess}. Pick another letter.")
guessed_letters.append(guess)
if lives == 0:
print (f"Game over. You lose. The word was '{chosen_word}'.")
else:
print (f"Congratulations. The word '{chosen_word}' is correct. You won!")