-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathguess_game.py
More file actions
31 lines (25 loc) · 961 Bytes
/
Copy pathguess_game.py
File metadata and controls
31 lines (25 loc) · 961 Bytes
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
import random
print("Welcome to the Guessing Game!")
print("Try to guess the word, one letter at a time.")
print("You have 10 attempts to guess the word correctly.")
print("Let's begin!")
word_bank = ['liverpool','chelsea','arsenal','manchester united','tottenham','manchester city']
word = random.choice(word_bank)
guessedWord = ['_'] * len(word)
attempts = 10
while attempts > 0:
print('\n Current word: ' + ' '.join(guessedWord))
guess = input("Enter a letter: ").lower()
if guess in word:
for i in range(len(word)):
if word[i] == guess:
guessedWord[i] = guess
print("Great guess!")
else:
attempts -= 1
print('Wrong guess! Attempts left: ' + str(attempts))
if '_' not in guessedWord:
print('\n Congratulations! You guessed the word: ' + word)
break
if attempts == 0 and '_' in guessedWord:
print('\nYou\'ve run out of attempts! The word was: ' + word)