-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
61 lines (46 loc) · 1.67 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from os import system
from words import word_list
from art import logo
import random
from art import stages
system('cls')
print(logo)
# - Randomly choose a word from the word_list and assign it to a variable called chosen_word.
chosen_word = random.choice(word_list)
word_length = len(chosen_word)
live = word_length
display = []
for _ in range(word_length):
display += "_"
end_of_game = False
while not end_of_game:
# Asking the user to guess a letter and assign their answer to a variable called guess. Make guess lowercase.
guess = input("Guess a letter: ").lower()
system('cls')
print(logo)
#Check guessed letter
for position in range(word_length):
letter = chosen_word[position]
#print(f"Current position: {position}\n Current letter: {letter}\n Guessed letter: {guess}")
if letter == guess:
display[position] = letter
#If guess is not a letter in the chosen_word,
#Then reduce 'lives' by 1.
#If lives goes down to 0 then the game should stop and it should print "You lose."
if guess not in chosen_word :
live -=1
if live == 0 :
end_of_game = True
print("You Lose !! ")
#Join all the elements in the list and turn it into a String.
print(f"{' '.join(display)}")
#Check if there are no more "_" left in 'display'. Then all letters have been guessed.
if "_" not in display:
end_of_game = True
print("You win.")
print(stages[live])
for letter in chosen_word:
if guess == letter :
print(guess,end="")
else:
print(" _ ",end="")