Question
PYTHON CODE !! NEED URGENTLY!! DUE IN 24 HOURS!! Please make sure your code output matches with the sample output given below. Make use of
PYTHON CODE !! NEED URGENTLY!! DUE IN 24 HOURS!!
Please make sure your code output matches with the sample output given below. Make use of online compiler or any python compiler!!
IMPORTANT!! Do not block this post by providing incorrect code.
FULL SAMPLE OUTPUT :
MUST ADHERE TO BELOW POINTS!
Please find the text files that are required below:
1. words.txt :
a able about above accept across act actually add admit afraid after afternoon again against age ago agree store story straight strange street strong struggle stuck student study stuff stupid such suck sudden suddenly suggest summer sun suppose sure surprise surround sweet table take taken talk tall teacher team tear teeth tell ten than thank that that's the their them themselves then there there's these they they'd they're thick thing think third this those though thought three threw throat through throw tie tight time tiny tire to today together told tomorrow tone tongue tonight too took top totally touch toward town track trail train tree trip trouble trust truth try turn TV twenty two type uncle under understand until up upon us use usual usually very visit voice wait wake walk wall want warm warn was wasn't watch water wave way we we'll we're we've wear week weird well went were weren't wet what what's whatever when where whether which while whisper white who whole why wide wife will wind window wipe wish with within without woke woman women won't wonder wood word wore work world worry worse would wouldn't wrap write wrong yeah year yell yes yet you you'd you'll you're you've young your yourself TRUE
2. art.txt :
_____ | | | | | | _____ | | | 0 | | | _____ | | | 0 | | | | _____ | | | 0 | /| | | _____ | | | 0 | /|\\ | | _____ | | | 0 | /|\\ | / | _____ | | | 0 | /|\\ | / \\ |
It would be great if you can write your code in Notepad++ or something so that the code is properly indented.
Thanks in Advance!! All the Best!!
In this homework you use the 1000 most common words in English (stored in "words.txt" to play the game Hangman. You can read more about the game see the Wikinedia article Setup * Create a Python file called hw07.py . Your hw07.py file must begin with comments in the following format (replace the name and email with your actual information: Name ISE15e, Spring 2819 USC email Homework 7 Requirements The assignment is broken into several parts-and it is recommended that you proceed in the order given Part 1: Main user input loop * Create a main function that has a loop that displays the user a menu and prompts the user for input. When the user enters a "1", the user should be told that the hangman game will start. We'll fill the actual game in as we go When the user enters a "2", the user should be told that they will add a word to the word list. Any other input will end the program. Output for Part 1 should look something like this (user input in red): Pick an option 1) Play Hangnan 2) Add to word 1ist ) Quit 1 Lets play HANGMAN! Pick an option 1 Play Hangman 2) Add to word list ) Quit > 2 Lets add a word to the list Pick an option 1 Play Hangman 2) Add to word 1ist ?) Quit Goodbye! Part 2: Load word file Create a function called "loadWords". It accepts 1 string as input -it contains the file name. It returns a list of strings where each string is 1 word from the input file. The function must read in the file line-by-line. Assume that each line has only 1 word, and each word must be added to the list (that you will return). Be sure to strip any extra spaces and insert the words in lower case. In main, create a string to hold the file name holding the word file. Prompt the user for the file name that holds the word list. In main, use the user's input and call your "loadWords" function. Save the output of the function (the list you return) in a variable in main. Be sure to test your program. You might want to try printing out the list of words that "loadWords" returns. Output for Part 2 should look something like this (user input in red) Word file name: Words.txt . Pick an option... 1) Play Hangman 2) Add to word list ) Quit Goodbye! Part 3: Load art file Create a function called "loadArt". It accepts 1 string as input- it contains the file name. It returns a list of strings where each string is a line of ASCII art. . The ASCll art in the file has a problem. Each new line (n") has an extra forward slash in front of it. You'll need to replace each occurrence of Wn" with In". You can use the replace function in strings . The same problem exists for the backslash. You must replace all the "M" with "". Do this after the previous replacement. Once the line from the input file has been cleaned up, add it to the list. Return the list with the file contents In main, create a string to hold the file name holding the art file. Prompt the user for the file In main, use the user's input and call your "loadArt" function. Save the output of the function . Be sure to test your program. To do this and make the art appear correctly, don't print out the name that holds the art. (the list you return) in a variable in main. whole list. Instead you'll need to create a loop then do something like "print(art[O]) where art is the variable that has my output from "loadArt Output for Part 3 should look something like this (user input in red) Word file name: Words.txt Art file name: art.txt Pick an option... 1) Play Hangman 2) Add to word list ?) Quit Goodbye! Part 4: Adding a word to the list Create a function called "addWord". It accepts 2 pieces of input -the word to add (as a string) and the list to add it to (as a list of strings). It returns true if the word was successfully added to the list, false if it was not. The function should check if the word is already in the list. If the word already exists, do nothing and return false If the word is not already in the list, add the word to the list. All the words in the list should be in lower case, so make sure the new word is also in lower case. The list is sorted in alphabetical order already, make sure the list stays alphabetized. Then return true. Change the code for option "2" in main. The option should prompt the user for a new word. Using the new function in an if statement we can attempt to add the word AND check if it added successfully in 1 step. If the result of the "addWord" function is true, the word added successfully let the user know this. If not, report to the user that the word already exists. Output for Part 4 should look something like this (user input in red) Word file name: Words.txt Art file name: art.txt . . Pick an option... 1) Play Hangman 2) Add to word list ?) Quit > 2 Enter a word to add to the word list: bel1 The word "bell" is already in the list! Pick an option... 1) Play Hangman 2) Add to word list ?) Quit Enter a word to add to the word list: Nathan Added the new word "nathan Pick an option... 1) Play Hangman 2) Add to word list ?) Quit Goodbye! Part 5: Storing the word list Create a function called "storeWords". It accepts 2 pieces of input-the file name (as a string) and the list of words (as a list of strings). This function will write the word list to the indicated file. The function returns nothing. It uses open and print to put the data back into the file. . Use the function in main, just before the program is over. Output for Part 5 should look something like this (user input in red) Word file name: words.txt Art file name: art.txt Pick an option... 1) Play Hangman 2) Add to word list ?) Quit > 2 Enter a word to add to the word list: Nathan Added the new word "nathan Pick an option... 1) Play Hangman 2) Add to word list ) Quit storing words... Goodbye! Note, that once this is over "nathan" should now be in "words.txt Part 6: Function setup to play hangman Create a function called "pickWord". It accepts the list of words (as a list of strings) as input. The function should pick a random word from the list and return that word (not it's index). Create a function called "genEmpties". It accepts a single word as input. It will generate and return a list with as many underscores ("_") as there are letters in the inputted word. For example, if the inputted word is "flower", then it will return a list with 6 underscores. Create a function called "setToString". It accepts a set with a series of letters stored in it as input. For example, the set may have the contents of "a", "u" and "g". The function must convert the set to a list, alphabetize the list, then generate a string. The string should contain each letter from the string, separated by spaces. Create a function called "gameOver". It accepts a list of letters as input (not a string). The function must analyze each letter in the list. If any of the items in the list is the underscore ("_" then the function should return false. If there are no underscores in the inputted list, it will return true. You should test each of these function by printing the result of them. . . Part 7: Loop to play hangman Inside of the main function, in the option to play hangman you'll need to setup a few variables: o Create a target word with the return result from "pickWord. This will be the word the user is trying to guess Create a user's word with the return result from "genEmpties". This represents the word as the user has guessed it. When the user successfully selects a letter, it's underscore will be replaced with the appropriate letter. Create a set to hold the letters the user has already guessed. As the user guesses letters, they will be added to the set. o o o Create a counter to keep track of the number of wrong guesses the user has made. It is a Goodidea to start the counter at 0. You can use this counter eventually to index into the art list. You'll need to create a loop that ends upon one of two conditions: When the wrong guess counter hits the last item in the art list When the user successfully guesses the word-for this, use the "gameOver" function. o o Inside the loop, do the following: o Display the art - use the wrong guesses counter to index into the list o Display the letters the user has already guessed (use the "setToString" function) o Display the user's word (the list with underscores ("_") in it. o Prompt the user for a new letter and store it. o If the user enters nothing, end the loop Output for Part 7 should look something like this (user input in red): Word file name: words.txt Art file name: art.txt Pick an option... 1) Play Hangman 2) Add to word list ?) Quit > 1 Lets play HANGMAN! You've already guessed these letters: Your word is _ -- - Letter please: o You've already guessed these letters: Your word is _ -- - Letter please: t You've already guessed these letters: Your word is _ -- - Letter please: Returning to main menu... Pick an option... 1) Play Hangman 2) Add to word list ?) Quit Storing words Goodbye! Part 8: Checking the user's answers Create a function called "checkGuess" It will accept 3 items for input. o The letter the user guessed (as a string) o o The word the user is trying to guess (as a string) The word as the user has guessed it so far (a list of strings, some of them are underscores ("_"), some of them are actual letters. It returns true if the letter inputted is in the word the user is trying to guess, false if it is not. If the letter is in the word, replace the underscores ("_") in the list with the guessed letter at the appropriate spot. Inside of the main function in the loop for playing the hangman game add the following: A check to make sure the user has entered a single character- if they haven't, warn the user, then start the game loop over again A check to see if the user has already guessed the letter (by checking for it in the guessed letters set)- if they've already guessed the letter, warn the user, and start the game loop over again. After checking for bad input (from the above two points), add the new letter to the guessed letter set. If the user's guessed letter is in the word, tell the user how many times the letter was found. Use the "checkGuess" function to do this. If the user's letter was not found, tell the user that (be sure to increment the wrong guess counter). o o o o Outside of the loop created for Part 7 (but still in the option 1 code), you will need to wrap up the game. Determine if the user guessed the word. You can either check for underscores ("_" in the list or check to see if the wrong guess counter reached the last index in the ASCII art list. If the user wins (guessed the word in time) tell the user. Otherwise, tell them they lost. Either way, tell the user what the word was. A Note on Style Be sure to comment your code. Also, you will lose points if your variable names are not meaningful. Make sure you use variable names that correspond to what you are storing in the variables. Full Sample Output Below is sample output for a full run-through of the program. As usual, you are not required to be as descriptive as the text below, so long as you perform and display the required calculations. User input is in red. Select an option: C:\ProgramDataAnaconda3 python.exe D:/Users/micro/Desktop/ISE499/hwe7a/hwe7.py Word file name: words.txt Art file name: art.txt Pick an option... 1) Play Hangman 2) Add to word list ) Quit 1 Lets play HANGMAN! You've already guessed these letters: your word is_ Letter please: a Found 1 "a"! You've already guessed these letters: your word is_a- Letter please:e Didn't find anye You've already guessed these letters: a e Your word isa" Letter please: i Didn't find any "i" You've already guessed these letters: Your word is "_a _- Letter please: e Found 1 "e"! You've already guessed these letters: a e Your word is "_a _e Letter please: i Didn't find any You've already guessed these letters: ael Your word is "_ a_e Letter please: o Didn't find any e You've already guessed these letters: a ei o Your word isa e Letter please: u Didn't find any u You've already guessed these letters: aeiou Your word is _a_e Letter please: s Found 1"S! You've already guessed these letters: Your word is "_ a s e Letter please: t Didn't find any "t" You've already guessed these letters: a e io st u Your word is "_ a s e Letter please: 1 Didn't find any "l" You've already guessed these letters: Your word is "_ a s e Letter please:m Didn't find any "m You lose! The word was "case" Pick an option.. 1) Play Hangman 2) Add to word list ) Quit > g Storing words... Goodbye! Deliverables 1. A compressed folder containing hw07.py Grading Rem Part 1: Main user input loop Part 2: Load word file Part 3: Load art file Part 4: Adding a word to the list Part 5: Storing the word list Part 6: Function setup to play hangman Part 7: Loop to play hangman Part 8: Checking the user's answers Total Points will be deducted for poor code style, or improper submission. Points 10 10 10 10 10 65Step 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