Question

Python guess letter game, if there is a word 'panda' then it will show to user...

Python guess letter game, if there is a word 'panda' then it will show to user '-----' at first. Then let user start to input letter, if user input 'a' then it should be show '-a--a'. And then if user input 'p' it should show 'pa--a'. If user input a wrong letter it should show an error. Program end until the whole letter been guess correctly.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE

import random

words = ['rainbow', 'computer', 'science', 'programming', 'python', 'mathematics', 'player', 'condition', 'reverse', 'water', 'board', 'geeks']

# Function will choose one random
# word from this list of words
word = random.choice(words)


print("Guess the characters")
guesses = ''

# any number of turns can be used here
turns = 12
while turns > 0:
# counts the number of times a user fails
failed = 0
  
# all characters from the input
# word taking one at a time.
for char in word:
# comparing that character with
# the character in guesses
if char in guesses:
print(char, end =" " )
else:
print("-", end = " ")
# for every failure 1 will be
# incremented in failure
failed += 1

if failed == 0:
# user will win the game if failure is 0
# and 'You Win' will be given as output
print("\nYou Win")

# this print the correct word
print("The word is: ", word)
break
  
# if user has input the wrong alphabet then
# it will ask user to enter another alphabet
guess = input("\nGuess a character:")
  
# every input character will be stored in guesses
guesses += guess
  
# check input with the character in word
if guess not in word:
turns -= 1
  
# if the character doesn’t match the word
# then “Wrong” will be given as output
print("Wrong")
  
# this will print the number of
# turns left for the user
print("You have", + turns, 'more guesses')
if turns == 0:
print("You Loose")

OUTPUT

Add a comment
Know the answer?
Add Answer to:
Python guess letter game, if there is a word 'panda' then it will show to user...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In PYTHON 3- Implement a subclass (described below) of "Word Guess", a variant of the game...

    In PYTHON 3- Implement a subclass (described below) of "Word Guess", a variant of the game Hangman. In this game, a word is first randomly chosen. Initially, the letters in the word are displayed represented by "_”.   For example, if the random word is "yellow”, the game initially displays "_ _ _ _ _ _”. Then, each turn, the player guesses a single letter that has yet to be guessed. If the letter is in the secret word, then the...

  • Create a script that presents a word-guessing game. Allow users to guess the word one letter at a...

    Create a script that presents a word-guessing game. Allow users to guess the word one letter at a time by entering a character in a form. Start by assigning a secret word to a variable. After each guess, print the word using asterisks for each remaining letter, but fill in the letters that the user guessed correctly. Store the user’s guess in a form field. For example, if the word you want users to guess is “suspicious” and the user...

  • Create a script that presents a word guessing game. Allow users to guess the word letter-by-letter by entering a character in a form. Start by assigning a secret word to a variable named $secret. Afte...

    Create a script that presents a word guessing game. Allow users to guess the word letter-by-letter by entering a character in a form. Start by assigning a secret word to a variable named $secret. After each guess, print the word using asterisks for each remaining letter but fill in the letters that the user guessed correctly. You need to store the user’s guess in a hidden text field name $hidden_guess. For example, if the word you want users to guess...

  • Write a guessing game where the user has to guess a secret number. After every guess...

    Write a guessing game where the user has to guess a secret number. After every guess the program tells the user whether their number was too large or too small. At the end the number of tries needed should be printed. It counts only as one try if they input the same number multiple times consecutively. Using PYTHON.

  • WRITE IN PYTHON: 2. Guess the Number The Goal: Similar to the first project, this project...

    WRITE IN PYTHON: 2. Guess the Number The Goal: Similar to the first project, this project also uses the random module in Python. The program will first randomly generate a number unknown to the user. The user needs to guess what that number is. (In other words, the user needs to be able to input information.) If the user’s guess is wrong, the program should return some sort of indication as to how wrong (e.g. The number is too high...

  • In PYTHON 3- Implement a subclass (described below) of "Word Guess", a variant of the game...

    In PYTHON 3- Implement a subclass (described below) of "Word Guess", a variant of the game Hangman. In this game, a word is first randomly chosen. Initially, the letters in the word are displayed represented by "_”.   For example, if the random word is "yellow”, the game initially displays "_ _ _ _ _ _”. Then, each turn, the player guesses a single letter that has yet to be guessed. If the letter is in the secret word, then the...

  • C++ Hangman (game) In this project, you are required to implement a program that can play...

    C++ Hangman (game) In this project, you are required to implement a program that can play the hangman game with the user. The hangman game is described in https://en.wikipedia.org/wiki/Hangman_(game) . Your program should support the following functionality: - Randomly select a word from a dictionary -- this dictionary should be stored in an ASCII text file (the format is up to you). The program then provides the information about the number of letters in this word for the user to...

  • JAVA PROGRAMMING (Game: hangman) Write a hangman game that randomly generates a word and prompts the...

    JAVA PROGRAMMING (Game: hangman) Write a hangman game that randomly generates a word and prompts the user to guess one letter at a time, as shown in the sample run. Each letter in the word is displayed as an asterisk. When the user makes a correct guess, the actual letter is then displayed. When the user finishes a word, display the number of misses and ask the user whether to continue to play with another word. Declare an array to...

  • Word Guessing Game Assignment Help Needed. This C++ (I'm using Visual Studio 2015) assignment is actually...

    Word Guessing Game Assignment Help Needed. This C++ (I'm using Visual Studio 2015) assignment is actually kind of confusing to me. I keep getting lost in all of the words even though these are supposed to instruct me as to how to do this. Can I please get some help as to where to start? Word guessing game: Overview: Create a game in which the user has a set number of tries to correctly guess a word. I highly recommend...

  • Simple JavaScript and HTML: You'll create a simple word guessing game where the user gets infinite...

    Simple JavaScript and HTML: You'll create a simple word guessing game where the user gets infinite tries to guess the word (like Hangman without the hangman, or like Wheel of Fortune without the wheel and fortune). Create two global arrays: one to hold the letters of the word (e.g. 'F', 'O', 'X'), and one to hold the current guessed letters (e.g. it would start with '_', '_', '_' and end with 'F', 'O', 'X'). Write a function called guessLetter that...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT