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....
Create a Hangman game using C++ by QT creator. please separate each code that will insert...
Create a Hangman game using C++ by QT creator. please separate each code that will insert in hider files and cpp files and use an accurate screeshoots if needed. Thanks in advance.
Please create a Hangman game in Java language. For this game a random word will be...
Please create a Hangman game in Java language. For this game a random word will be selected from the following list (abstract, cemetery, nurse, pharmacy, climbing). You should keep a running tab of the user’s score and display it on screen; the user begins with 100 points possible if they correctly guess the word without any mistakes. For every incorrect letter which is guessed, 10 points should be taken away from what is left of their total possible points. For...
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...
How would I create a Hangman game that chooses  a random word and the player needs to...
How would I create a Hangman game that chooses  a random word and the player needs to guess it, letter by letter using  JavaScript and jQuery to allow user interaction. The content and the style of the page must be updated based on user’s input.
Using Python, create a program that will act as a number convertor. This program will convert...
Using Python, create a program that will act as a number convertor. This program will convert an input decimal integer into binary and hexadecimal formats. a) Define a main function named numberconvertor(). Inside the main function, write all the logic of your code. [5% marks] b) Looping indefinitely (Hint: use infinite while loop), the program should give the user the 3 options given below and allow the user to select one among them. [15% marks] 1. converting a decimal number...
How to do this in Python (using Lists): Create a python program that allows a user...
How to do this in Python (using Lists): Create a python program that allows a user to display, sort and update as needed a List of U.S States containing the State Capital and State Bird. You will need to embed the State data into your Python code. The user interface will allow the user to perform the following functions: 1. Display all U.S. States in Alphabetical order along with Capital and Bird 2. Search for a specific state and display...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT