-
Notifications
You must be signed in to change notification settings - Fork 0
/
secret_word_game.py
57 lines (44 loc) · 1.24 KB
/
secret_word_game.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
import os
os.system('cls')
correct_letters = ''
attempts = 6
numbers = '1234567890'
while True:
secret_word = input('type the secret word: ')
if secret_word in numbers:
print('Only letters!!')
continue
else:
break
os.system('cls')
while True:
digited_word = input('type a letter: ')
if len(digited_word) > 1:
print('type only one word')
continue
if digited_word in numbers:
print('Only letters!!')
continue
if digited_word in secret_word:
correct_letters += digited_word
generated_word = ''
for secret_letter in secret_word:
if secret_letter in correct_letters:
generated_word += secret_letter
else:
generated_word += '*'
if digited_word in secret_word:
print('Correct letter!!')
else:
print('Wrong letter')
attempts -= 1
print(f'Attempts left {attempts}')
if attempts == 0:
os.system('cls')
print('You lost!!')
break
print(generated_word)
if generated_word == secret_word:
os.system('cls')
print(f'You guessed the word, it was {secret_word}')
break