Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

check_input.py def get_int(prompt): Repeatedly takes in and validates user's input to ensure that it is an integer. Args: prompt: string to display to the user

image text in transcribed

image text in transcribedimage text in transcribedimage text in transcribed

check_input.py

def get_int(prompt): """Repeatedly takes in and validates user's input to ensure that it is an integer. Args: prompt: string to display to the user to prompt them to enter an input. Returns: The valid positive integer input. """ val = 0 valid = False while not valid: try: val = int(input(prompt)) valid = True except ValueError: print("Invalid input - should be an integer.") return val def get_positive_int(prompt): """Repeatedly takes in and validates user's input to ensure that it is a positive (>= 0) integer. Args: prompt: string to display to the user to prompt them to enter an input. Returns: The valid integer input. """ val = 0 valid = False while not valid: try: val = int(input(prompt)) if val >= 0: valid = True

else: print("Invalid input - should not be negative.") except ValueError: print("Invalid input - should be an integer.") return val def get_int_range(prompt, low, high): """Repeatedly takes in and validates user's input to ensure that it is an integer within the specified range. Args: prompt: string to display to the user to prompt them to enter an input. low: lower bound of range (inclusive) high: upper bound of range (inclusive) Returns: The valid integer input within the specified range. """ val = 0 valid = False while not valid: try: val = int(input(prompt)) if val >= low and val

while not valid: val = input(prompt).upper() if val == "YES" or val == "Y": return True elif val == "NO" or val == "N": return False else: print("Invalid input - should be a 'Yes' or 'No'.")

Hangman Create a program that plays the game 'Hangman'. Randomly select a 5-letter word from the 'dictionary.py' file to use as the word the user needs to guess. At the beginning, display the empty gallows and 5 blank spaces that represents the word they are supposed to guess. Then, repeatedly prompt the user to guess a letter that's in the word. If they guess correctly, fill in the correct blank spaces with that letter. If they guess incorrectly, add a part of the hangman to the gallows and add the letter to the list of incorrect guesses. If they do not guess the word by the time the hangman is complete ( 6 incorrect turns), then they lose. As a hint to the user, also display the list of letters that they haven't used yet. Create the following functions for your program: 1. display_gallows (num_incorrect) - given the number of incorrect guesses the user has made, display the state of the hangman on the gallous (ex. zero incorrect guesses should show an empty gallows, 6 incorrect guesses should show the complete hanged man). 2. display_correct (correct) - given the list of correct guesses, display each of the letters in their correct locations separated by spaces. 3. display_incorrect(incorrect) - given the list of incorrect guesses, sort the list and then display each letter separated by spaces. 4. display_letters_remaining(incorrect, correct) - given the list of incorrect guesses and the list of correct guesses, display the list of remaining letters in the alphabet to choose from. In your main function, create a loop that repeats until the user chooses to quit. Choose a random word from the words list (this file is given on Canvas, include the list by putting ' f rom dictionary import worda' at the top of your program), then create two lists, one for the incorrect guesses (which starts off empty), and the other for the correct guesses (starts with 5 blank spaces ('_')). Create two counters, one for the number of correct guesses made, and the other for the number of incorrect guesses. Create a loop that will repeat until the user guesses all 5 letters in the word, or until the user has made 6 incorrect guesses. Every round, display the incorrect guesses, the gallows, the correct guesses, the letters remaining, and then prompt the user to enter their guess. Check to make sure that all user input is valid (ie. it is a letter AZ, and not a letter they've already guessed). If the guess was correct, add it to the list of correct guesses in the correct spot(s), if it was not, add it to the list of incorrect guesses and tally the correct or incorrect guess. Display whether they won or lost, if they lose, show the correct answer. Letters yemainingl BBDDGHJK Enter a letter: E Incorzect! Lettera remaining: A B BDFGKFOF Z W MPQR V %YZ Incorrect selections: 3 Enter a letter: 1 Incorrect! I. MOPQR IV V%xz Incorrect selections: I S I Enter a letter: t Letvers remaining ABCDFGHIJK Incorxect! Incorrect selections: S T Enter a lettert p Incorrect! =:=E==E=11/11111111101 - E-.- Incorrect selections: I PS I Detterg remaining ADDB I J Z IN OPQR R V%x%z Enter a letter: t Tetvers gemaining: BDFGIH You have already used that letter. M it QQR R V V o Yz Incorrect selections: 3 I Enter a letter: r Correct! Incorrect selections: I P I Notes: 1. Place your name, date, and a brief description in a comment at the top of your program. 2. Use the check_input module provided on Canvas to check the user's input for getting the yeso input (not the letter quess input). 3. Include the 'dictionary.py' file by placing 'from dietionary import wordi' at the top of your program. 4. Use the random module to choose a random word from the words list. 5. Do not add any additional functions or parameters to your code or use global variables. 6. Please read through the Coding Standards document posted on Canvas for guidelines on how to format your program. 7. Use docstrings to document your functions. 8. Add brief comments to your program to describe sections of your code. 9. Your output should be similar to the above, but you can design your gallows as you like. 10. Thoroughly test your program before submitting: a. Make sure that your program generates a different word from the list every time you run your program. b. Make sure that it correctly displays the list of incorrect and correct guesses. c. Make sure that the correct letters show up at the correct locations. d. Make sure the list of incorrect letters are sorted. e. Make sure the number of incorrect letters is the same as the number of parts of the hangman. f. Make sure that the game ends when the user guesses the correct word or they got 6 incorrect guesses, and it correctly reports that they won or lost. g. Make sure that the program repeats if the user selects 'Yes', and ends the program if the user selects 'No'. "BEACH", "CHAIR", "Clock", "DRess", "SKATE", "RADio", "RIVER", "SHEEP", "SHAPE", "SKIRT", "StoRE", "SHOES", "MOOSE", "BEADS", "WHEEL", "PIGGY", "SKUNK", "JELLO", "FRIES", "CHIPS", "GAMES", "HANDS", "ElBow", "KNEES", "SODAS", "DESKS", "BowlS", "PURSE", "WORDS", "THREE", "SEven", "EIGHT", "PEARS", "BEARS", "SYRUP", "PIZZA", "SOCKS"]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Murach's SQL Server 2012 For Developers

Authors: Bryan Syverson, Joel Murach, Mike Murach

1st Edition

1890774693, 9781890774691

More Books

Students also viewed these Databases questions

Question

Explain the importance of Human Resource Management

Answered: 1 week ago

Question

Discuss the scope of Human Resource Management

Answered: 1 week ago

Question

Discuss the different types of leadership

Answered: 1 week ago

Question

Write a note on Organisation manuals

Answered: 1 week ago

Question

=+10. Did you clearly project the brand's USP?

Answered: 1 week ago