0% found this document useful (0 votes)
56 views

Gguess The Word Lab

This document contains the code for a Python guessing game where a user enters a secret word and the program displays underscores representing the letters. The program then prompts the user to guess letters and updates the display after each turn. It tracks correct and incorrect guesses until the user guesses the full word or runs out of attempts, at which point the user is asked if they want to play again.

Uploaded by

api-536596983
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views

Gguess The Word Lab

This document contains the code for a Python guessing game where a user enters a secret word and the program displays underscores representing the letters. The program then prompts the user to guess letters and updates the display after each turn. It tracks correct and incorrect guesses until the user guesses the full word or runs out of attempts, at which point the user is asked if they want to play again.

Uploaded by

api-536596983
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

In [ ]: user_word = input("Enter the secret word: ")

print("Let's play Guess the Word. Guess a letter that you think is in the word. Y
print()
print()
print()
print()
secret_word = list(user_word)
word_so_far = len(user_word) * ['_']
game = True
list_of_guessed = []
incorrect_guesses = 0
print(word_so_far)

while (game == True):


correct_this_round = 0
guess = input("Enter a guess: ")

for x in range(len(secret_word)):
if (guess == secret_word[x]):
word_so_far[x] = guess
print("Yes!")
print(word_so_far)
correct_this_round +=1

for x in range (len(list_of_guessed)):


if guess == list_of_guessed[x]:
print('You already guessed this letter! Guess again.')
else:
list_of_guessed.append(guess)
print('Letters already guessed: {}'.format(list_of_guessed))

if (correct_this_round == 0):
incorrect_guesses+=1
print ('Wrong Guess!')
print('You have made {} incorrect guesses.'.format(incorrect_guesses))

if (secret_word == word_so_far):
print ("Yay! You've guessed the right word.")
play_again = input('Would you like to play again? Answer yes or no.')

if (play_again == 'yes' or play_again == 'Yes'):


incorrect_guesses = 0
user_word = input('Enter the secret word:')
secret_word = list(user_word)
word_so_far = len(user_word) * ['_']
game == True

else:
game == False
print('Thanks for playing!')

if (incorrect_guesses == 6):
print("You've had too many wrong guesses! Game over.")
play_again = input('Would you like to play again? Answer yes or no.')

if (play_again == 'yes' or play_again == 'Yes'):


incorrect_guesses = 0
user_word = input('Enter the secret word:')
secret_word = list(user_word)
word_so_far = len(user_word) * ['_']
game == True

else:
game == False
print('Thanks for playing!')

Enter the secret word: hello


Let's play Guess the Word. Guess a letter that you think is in the word. You on
ly have 6 chances to guess a wrong letter. Let's begin!

['_', '_', '_', '_', '_']


Enter a guess: h
Yes!
['h', '_', '_', '_', '_']
Enter a guess: e
Yes!
['h', 'e', '_', '_', '_']
Enter a guess: l
Yes!
['h', 'e', 'l', '_', '_']
Yes!
['h', 'e', 'l', 'l', '_']
Enter a guess: o
Yes!
['h', 'e', 'l', 'l', 'o']
Yay! You've guessed the right word.
Would you like to play again? Answer yes or no.no
Thanks for playing!

In [ ]:

You might also like