-
Notifications
You must be signed in to change notification settings - Fork 0
/
holiday_guess_the_word.py
55 lines (38 loc) · 1.31 KB
/
holiday_guess_the_word.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
# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
import random
guesses_left = 9
words = ['santa','gifts','sugar', 'angel','snowflake','star','reigndeer','cookie','tree', 'candle']
secret_word = random.choice(words)
clue = list('?' * len(secret_word))
symbol = "🎄"
guessed_word_correctly = False
def update_clue(guessed_letter, secret_word):
index = 0
while index < len(secret_word):
if guessed_letter == secret_word[index]:
clue[index] = guessed_letter
index = index + 1
def listToString(mylist):
cluestring = ' '
return cluestring.join(mylist)
print("Guess the word associated with winter holidays! ")
while guesses_left > 0:
print(listToString(clue))
print("Guesses left: " + symbol * guesses_left)
guess = input("Guess a letter or the whole word: ")
if guess == secret_word:
guessed_word_correctly = True
break
if guess in secret_word:
update_clue(guess, secret_word)
else:
print('Incorrect. You lose a life!')
guesses_left = guesses_left - 1
if guessed_word_correctly:
print("You win! The secret word was " + secret_word)
else:
print("You lose! Womp, womp. The secret word was " + secret_word)