Question

In: Computer Science

In python Using the example code from the HangMan program in our textbook, create a Word...

In python Using the example code from the HangMan program in our textbook, create a Word Guessing Game of your choice. Design a guessing game of your own creation. Choose a theme and build your words around that theme. Keep it simple.

Note: I would highly recommend closely reviewing the HangMan code and program from Chapter 10 before starting work on this project. You can run the program via my REPL (Links to an external site.).

Using python Similar to our Number Guessing game, be sure to allow the player the option to keep playing and keep score. You can design the game however you see fit but it must meet these requirements:

General Requirements

  • Remember to comment your code - include your name, date, class, and assignment title.
  • Provide comments throughout your program to document your code process.
  • Create a greeting/title to your program display output.
  • Your program should ask the player if they wish to play again.
  • Be creative! Have fun with this. Don't overthink it.

Word lists

  • You must have wordlists totaling at least 30 words to select from divided into themes or topics that you have identified. For example, say your words are all related to United States state names and world country names. You might choose to have one list named statelist and one list named countrylist. Each list might contain 15 words. Break these themes/topics into whatever works best but be sure to have at least a total of 30 words to work from.
  • Your game should randomly choose one of the words in the wordlists.

Output in python test and paste code

  • The player should be given the theme/topic of the word.
  • The player should be told how many letters the word contains.
  • The player should be shown a list of the letters that they have guessed already.
  • Output the correct guesses and location of the letters in the word. For example say the word is banana. The user has guesses the letter A as their first guess. Your output will display something like _ a _ a _ a so that the player can guess the word.
  • Your program should keep score of wins/losses and display them to the player.

Guesses in python code show

  • The player should be given ten guesses. *Note depending on the complexity of your theme/topic area you may wish to modify the maximum guesses.
  • The program should ask for a letter guess. Validate that the player inputs only 1 letter in their guess. Handle other inputs with feedback and a request to try again.
  • Your program should REMOVE the word they just played from the wordlist so they do not get the same word twice.

Think the program through

Break this down into smaller sized concepts first. Walk through the program functions step by step. Here is some of my thought processes to get you started. Thank you for helping me

  • First create your word lists and organize them by theme/topic. Maybe I want my game to be "Things You Find in a Grocery Store" and I will have 3 lists - fruits, vegetables and proteins. I will create each of my list structures and come up with 10 words for each list. fruits =["banana", "apple", "grapes", "orange", "pear", "peach", "plum"] etc.
  • Then I will try to randomly select an index from my list. I can use the random module to help me and get a value between 0 and the length of the list -1 (to take into account that the index starts at 0).
  • Once I have that part of the program working, I would celebrate my win and take a little break.
  • Next, I will store the random word from my list to a variable so that I can compare the input guesses against that word. This is where I will need to make use of string functions from Chapter 10 and use the Hangman code for inspiration.
  • I would use string functions like find() to search and find if the letter guess found a match.
  • If a match was found, I would print out a message.
  • If a match wasn't found, I would print out a message, and store the guessed letter to a list.
  • I would then output the word with the correctly guessed letters in the position they should be in.
  • and so on... until the game worked and produced the correct output.


  • Here is the book hangman code to refere to:

    import wordlist

    # Get a random word from the word list
    def get_word():
    word = wordlist.get_random_word()
    return word.upper()

    # Add spaces between letters
    def add_spaces(word):
    word_with_spaces = " ".join(word)
    return word_with_spaces

    # Draw the display
    def draw_screen(num_wrong, num_guesses, guessed_letters, displayed_word):
    print("-" * 79)
    print("Word:", add_spaces(displayed_word),
    " Guesses:", num_guesses,
    " Wrong:", num_wrong,
    " Tried:", add_spaces(guessed_letters))

    # Get next letter from user
    def get_letter(guessed_letters):
    while True:
    guess = input("Enter a letter: ").strip().upper()
      
    # Make sure the user enters a letter and only one letter
    if guess == "" or len(guess) > 1:
    print("Invalid entry. " +
    "Please enter one and only one letter.")
    continue
    # Don't let the user try the same letter more than once
    elif guess in guessed_letters:
    print("You already tried that letter.")
    continue
    else:
    return guess

    # The input/process/draw technique is common in game programming
    def play_game():
    word = get_word()
      
    word_length = len(word)
    remaining_letters = word_length
    displayed_word = "_" * word_length

    num_wrong = 0   
    num_guesses = 0
    guessed_letters = ""

    draw_screen(num_wrong, num_guesses, guessed_letters, displayed_word)

    while num_wrong < 10 and remaining_letters > 0:
    guess = get_letter(guessed_letters)
    guessed_letters += guess
      
    pos = word.find(guess, 0)
    if pos != -1:
    displayed_word = ""
    remaining_letters = word_length
    for char in word:
    if char in guessed_letters:
    displayed_word += char
    remaining_letters -= 1
    else:
    displayed_word += "_"
    else:
    num_wrong += 1

    num_guesses += 1

    draw_screen(num_wrong, num_guesses, guessed_letters, displayed_word)

    print("-" * 79)
    if remaining_letters == 0:
    print("Congratulations! You got it in",
    num_guesses, "guesses.")   
    else:
    print("Sorry, you lost.")
    print("The word was:", word)

    def main():
    print("Play the H A N G M A N game")
    while True:
    play_game()
    print()
    again = input("Do you want to play again (y/n)?: ").lower()
    if again != "y":
    break

    if __name__ == "__main__":
    main()

Solutions

Expert Solution

here, In the word guessing python game, the user will guess the word that one has defined at the beginning like word 'tree', ' mango; etc,

users have the following benefits of this game:

  • They will play again if they want.
  • The game will ask the user name first then the user guesses the word.
  • Users will get to know how many attempts have been left after spending every attempt.
  • If the user will guess input that is other than alphabets, then the game will stop.
  • The game will let the user know if they type the same character of guess word twice.

Code of a word guessing game:

The output of the code is as:

i hope it helps..

If you have any doubts please comment and please don't dislike.

PLEASE GIVE ME A LIKE. ITS VERY IMPORTANT FOR ME


Related Solutions

Using Python code create a program only with beginners code. You are taking online reservations at...
Using Python code create a program only with beginners code. You are taking online reservations at the The inn Ask for your client’s name and save in a variable Ask how many nights your client will be staying and save in a variable Room rental is $145 per night Sales tax is 8.5% Habitation tax is $5 per night (not subject to sales tax) Print out: Client’s name Room rate per night Number of nights Room cost (room rate *...
This is using Python, it is utilizing code from a Fraction class to create a Binary...
This is using Python, it is utilizing code from a Fraction class to create a Binary Class Please leave comments so I may be able to learn from this. Instruction for Binary Class: Exercise 6.18: Design an immutable class BinaryNumber, in the style of our Fraction class. Internally, your only instance variable should be a text string that represents the binary value, of the form '1110100'. Implement a constructor that takes a string parameter that specifies the original binary value....
What would the Python code be to create the following working program using turtle: -Make 4...
What would the Python code be to create the following working program using turtle: -Make 4 turtles that are YELLOW, and 4 turtles that are GREEN. Create these turtles using one or more lists. -Make the yellow turtles start at a different randomized location somewhere on the left side of the screen within the range of (-100,100) and (0, -100) -Make the green turtles start at a different randomized location somewhere on the right side of the screen within the...
Code using R or Python We observe from our campus the temperature and count the number...
Code using R or Python We observe from our campus the temperature and count the number of squirrels. Our observations are T = [52, 52, 50, 54, 50, 52, 54, 80, 80] Sq = [8, 10, 6, 9, 6, 12, 12, 1, 0] a) What is the covariance of these vectors? (1point) b) What is the covariance matrix? (1point) c) What is the correlation coefficient? (1point) d) Find the coefficient of determination? (1point) e) Can you make any statement or...
Create a program with the exception example code from Hour14Exceptions.java the Hour14Exceptions shows examples of string...
Create a program with the exception example code from Hour14Exceptions.java the Hour14Exceptions shows examples of string and number exception handling, as well as a user defined exception CREATE A NEW PROGRAM that demonstrates Any 2 of the following 3 choices: 1 numeric and 1 string exception make the program require 1 input argument and throw an exception if there are no command line arguments passed in. In the exception, inform the user that an input argument is required. (You can...
can you please create the code program in PYTHON for me. i want to create array...
can you please create the code program in PYTHON for me. i want to create array matrix Nx1 (N is multiple of 4 and start from 16), and matrix has the value of elements like this: if N = 16, matrix is [ 4 4 4 4 -4 -4 -4 -4 4 4 4 4 -4 -4 -4 -4] if N = 64, matrix is [8 8 8 8 8 8 8 8 -8 -8 -8 -8 -8 -8 -8...
The code that creates this program using Python: Your program must include: You will generate a...
The code that creates this program using Python: Your program must include: You will generate a random number between 1 and 100 You will repeatedly ask the user to guess a number between 1 and 100 until they guess the random number. When their guess is too high – let them know When their guess is too low – let them know If they use more than 5 guesses, tell them they lose, you only get 5 guesses. And stop...
Python Explain Code #Python program class TreeNode:
Python Explain Code   #Python program class TreeNode:    def __init__(self, key):        self.key = key        self.left = None        self.right = Nonedef findMaxDifference(root, diff=float('-inf')):    if root is None:        return float('inf'), diff    leftVal, diff = findMaxDifference(root.left, diff)    rightVal, diff = findMaxDifference(root.right, diff)    currentDiff = root.key - min(leftVal, rightVal)    diff = max(diff, currentDiff)     return min(min(leftVal, rightVal), root.key), diff root = TreeNode(6)root.left = TreeNode(3)root.right = TreeNode(8)root.right.left = TreeNode(2)root.right.right = TreeNode(4)root.right.left.left = TreeNode(1)root.right.left.right = TreeNode(7)print(findMaxDifference(root)[1])
Create a python program that prints the series from 5 to 500.
Create a python program that prints the series from 5 to 500.
USING PYTHON Write a program to create a number list. It will call a function to...
USING PYTHON Write a program to create a number list. It will call a function to calculate the average values in the list. Define main ():                        Declare variables and initialize them                        Create a list containing numbers (int/float)                        Call get_avg function that will return the calculated average values in the list.                                       Use a for loop to loop through the values in the list and calculate avg                        End main()
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT