ask \"do you want to play hangman\" read answer while answer is yes get random w
ID: 3620842 • Letter: A
Question
ask "do you want to play hangman"read answer
while answer is yes
get random word to guess
play hang man with random word to guess
ask "do you want to play hang man again"
read answer
end while
display goodbye message
void playHangman(secret_word)
mask = generateWordMask(secret_word’s length)
maximum_wrong_guess_count =
computeMaximumWrongGuessCount(secret_word)
already_guessed_list = initializeAlreadyGuessedList
assign 0 to wrong_guess_count
assign 0 to right_guess_count
repeat
guess = readGuessFromUser
number_of_occurrences = countOccurrences(guess, secret_word)
if number_of_occurrences > 0 then
add number_of_occurrences to right guess count
updateMask(guess, secret_word, mask)
add guess to already_guessed_list
else
add 1 to wrong_guess_count
add guess to already_guessed_list
end if
until wrong_guess_count > maximum_wrong_guess_count or
right_guess_count = secret_word's length
if right_guess_count = secret_word's length then
display "you win message"
else
display "you lose message"
display secret_word
end if
end playHangman
number search(target, source, start)
start = position
while position < source’s length and target ? source[position]
add 1 to position
end while
if position < source’s length then
return position
else
return –1
end if
end search
number countOccurences(value, source)
counter = 0
start = 0
while search(value, source, start) ? -1
add 1 to counter
start = start + 1
end while
return counter
end countOccurrences
void updateMask(guess, word, mask)
start = 0
position = search(guess, word, start)
while position ? -1
remove character at position
insert guess at position
end while
end update mask
character readGuess(all ready guessed list)
read guess from interactive input stream
while search(guess already guessed list) succeeds
display appropirate message
read guess from interactive input stream
end while
return guess
end readGuess
Explanation / Answer
please rate - thanks as in the past create a file with words in it to be used for inputRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.