Question: We re going to define a few useful methods for you. Read their implementation and make sure they make sense. Save & Run Original -
Were going to define a few useful methods for you. Read their implementation and make sure they make sense.
Save & Run
Original of
import json
# Repeatedly asks the user for a number between low & high inclusive
def getNumberBetweenprompt low, high:
userinp inputprompt # ask the first time
while True:
try:
n intuserinp # try casting to an integer
if n low:
errmessage 'Must be at least formatlow
elif n high:
errmessage 'Must be at most formathigh
else:
return n
except ValueError: # The user didn't enter a number
errmessage fuserinp is not a number.
# If we haven't gotten a number yet, add the error message
# and ask again
userinp inputferrmessage
prompt
# Spins the wheel of fortune wheel to give a random prize
# Examples:
# "type": "cash", "text": $ "value": "prize": "A trip to Ann Arbor!"
# "type": "bankrupt", "text": "Bankrupt", "prize": false
# "type": "loseturn", "text": "Lose a turn", "prize": false
def spinWheel:
with openwheeljson", r as f:
wheel json.loadsfread
return random.choicewheel
# Returns a category & phrase as a tuple to guess
# Example:
# Artist & Song", "Whitney Houston's I Will Always Love You"
def getRandomCategoryAndPhrase:
with openphrasesjson", r as f:
phrases json.loadsfread
category random.choicelistphraseskeys
phrase random.choicephrasescategory
return category phrase.upper
# Given a phrase and a list of guessed letters, returns an obscured version
# Example:
# guessed: LBERNPKXZ
# phrase: "GLACIER NATIONAL PARK"
# returnsLER NNL PRK
def obscurePhrasephrase guessed:
rv
for s in phrase:
if s in LETTERS and s not in guessed:
rv rv
else:
rv rvs
return rv
# Returns a string representing the current state of the game
def showBoardcategory obscuredPhrase, guessed:
return
Category:
Phrase:
Guessed: formatcategory obscuredPhrase, joinsortedguessed
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
