Answered step by step
Verified Expert Solution
Question
1 Approved Answer
# Solve the problems below # The number of turns allowed is a global constant NB_TURNS = 10 def pick_random_word(): Opens the words.txt
# Solve the problems below # The number of turns allowed is a global constant NB_TURNS = 10 def pick_random_word(): """Opens the words.txt file, picks and returns a random word from the file""" #CODE HERE ! return selected_word def show_letters_in_word(word, letters): """ This function RETURNS A STRING. This function scans the word letter by letter. First, make sure word is uppercase, and all letters are uppercase. If the letter of the word is in the list of letters, keep it. Otherwise, replace it with an underscore (_). DO NOT USE PRINT! Example: >>> show_letters_in_word("VANCOUVER", ["A", "V"]) 'V A _ _ _ _ V _ _' >>> show_letters_in_word("TIM", ["G", "V"]) '_ _ _' >>> show_letters_in_word("PIZZA", ["A", "I", "P", "Z"]) 'P I Z Z A' """ #CODE HERE return my_string def all_letters_found(word, letters): """Returns True if all letters in word are in the list 'letters'""" return False def main(turns): """ Runs the game. Allows for "turns" loops (attempts). At each turn: 1. Ask the user for a letter 2. Add the letter to the list of letters already tried by the player 3. If the letter was already tried, ask again 4. Use the show_letters_in_word function to display hints about the word 5. Remove 1 to the number of tries left 6. Check if the player - won (= word has been found) - lost (= word has not been found, no tries left) """ # CODE HERE pass if __name__ == "__main__": main(NB_TURNS) Test to see if it works import pytest from hangman import show_letters_in_word, all_letters_found def test_show_letters_1(): assert show_letters_in_word("Vancouver", ["A", "V"]) == "V A _ _ _ _ V _ _" assert show_letters_in_word("Vancouver", ["a", "v"]) == "V A _ _ _ _ V _ _" assert show_letters_in_word("TIM", ["G", "V"]) == "_ _ _" assert show_letters_in_word("PIZZA", ["A", "I", "P", "Z"]) == "P I Z Z A" def test_all_letters(): assert all_letters_found("PIZZA", ["A", "I", "P", "Z"]) is True assert all_letters_found("PIZZA", ["A", "I", "P", "Z", "K", "T"]) is True assert all_letters_found("VANCOUVER", ["A", "V"]) is False Words.txt file absurd abyss affix askew avenue awkward axiom azure banjo bayou bikini blitz boggle boxcar boxful buffalo buffoon buxom buzzard buzzing caliph cobweb croquet crypt curacao cycle dirndl disavow duplex dwarves equip euouae exodus faking fixable fjord flyby fuchsia funny gabby galaxy gazebo giaour gizmo glyph gnarly gnostic gossip haiku hyphen icebox injury ivory ivy jackpot jaywalk jazzy jelly jigsaw jinx jockey jogging joking jovial joyful juicy jukebox jumbo kayak kazoo keyhole khaki kiosk kitsch klutz larynx lengths lucky luxury lymph marquis matrix mystify naphtha nymph onyx ovary oxidize oxygen pajama phlegm pixel pizazz polka pshaw psyche puppy quartz queue quips quiz quizzes quorum rhubarb rhythm scratch shiv snazzy sphinx spritz squawk staff stretch stymied subway swivel topaz twelfth unknown unzip uptown vixen vodka voodoo vortex walkway waltz wave wavy waxy wheezy whiskey wimpy wizard woozy wyvern yippee yoked yummy zephyr zigzag zilch zipper zodiac zombie
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started