Question: Using the provided code in python, how do I edit the code to reflect the expect output below: Expected Output # 1 : A game
Using the provided code in python, how do I edit the code to reflect the expect output below:
Expected Output #: A game not showing details
What word length?
You have guesses remaining
Guessed letters: set
Current hint:
Enter a letter: a
Im sorry a is not in the word.
You have guesses remaining
Guessed letters: a
Current hint:
Enter a letter: b
Im sorry b is not in the word.
You have guesses remaining
Guessed letters: ab
Current hint:
Enter a letter: c
Im sorry c is not in the word.
You have guesses remaining
Guessed letters: abc
Current hint:
Enter a letter: d
Im sorry d is not in the word.
You have guesses remaining
Guessed letters: adbc
Current hint:
Enter a letter: e
Im sorry e is not in the word.
You have lost. The word was onyx
Provided Code:
import random
def loadwordshangmanwords:
with openhangmanwords, r as f:
return linestriplower for line in f if lenlinestrip
def maskwordword guessed:
return joinletter if letter in guessed else for letter in word
def partitionwords guessed:
partitions
for word in words:
hint maskwordword guessed
if hint not in partitions:
partitionshint set
partitionshintaddword
return partitions
def maxpartitionpartitions:
maxsize maxlenwords for words in partitions.values
candidates hint for hint, words in partitions.items if lenwords maxsize
minrevealed minhintcount for hint in candidates
besthints hint for hint in candidates if hint.count minrevealed
return random.choicebesthints if lenbesthints else besthints
def playhangmanwordlist, wordlength, displaydetailsFalse:
words word for word in wordlist if lenword abswordlength
guessed set
incorrectguesses
maxincorrect
currenthint abswordlength
while incorrectguesses maxincorrect and in currenthint:
printfCurrent word: currenthint
guess inputGuess a letter: lower
if lenguess or not guess.isalpha or guess in guessed:
printInvalid guess. Try again."
continue
guessed.addguess
# Partition the word list based on the guessed letter
partitions partitionwords guessed
nexthint maxpartitionpartitions
words partitionsnexthint
if currenthint nexthint:
incorrectguesses
printfIncorrect Total incorrect guesses: incorrectguesses
else:
printCorrect guess!"
if displaydetails:
printPartitions:k: lenv for k v in partitions.items
currenthint nexthint
if not in currenthint:
printfCongratulations You've guessed the word: currenthint
else:
printGame over! You've reached the maximum incorrect guesses."
printfThe possible words were: joinwords
def main:
wordlength intinputEnter the word length negative for detailed mode:
displaydetails wordlength
wordlength abswordlength
wordlist loadwordshangmanwords.csv
if not wordlist:
printfNo words found with length wordlength Exiting."
return
playhangmanwordlist, wordlength, displaydetails
if namemain:
main
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
