Advertisement
brianops1

Work

Apr 30th, 2018
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.89 KB | None | 0 0
  1. Lab Project 4
  2. Lesson 1
  3. You need to modify the code below so it will gradually display a Mr. Potato Head just as there is a person being gradually hanged in this sample code highlighted in yellow. Use your creativity on how to shape text-characters a basic potato which can be added on to in each successive Multi-line String entry. This kind of display technique is referred to as ASCII art because ASCII (American Standard Code for Information Interchange) is an acronym of an organization which established a numerical value for each and every text character on the keyboard. The computer industry worldwide decided on creating this table of numbers and characters which associate a specific number with each text based character so the computer will know what to print to the screen.
  4.  
  5. You need to follow the same syntax guidelines spelled out in the code located here but you do not need to have the same number of String entries. In fact, if you add more string entries it will allow the player to have more guesses before they lose. See if you can tell why by examining the sample code of the entire hangman.py program.
  6.  
  7. Note: As an extra challenge trace the code in hangman.py to see where you would have to adjust the code if you changed the name of the Multi-line String from “HANGMANPICS” to “POTATOPICS”.
  8.  
  9. Lesson 2
  10. Change the display so that it prints the correct letters and missed letters in caps. Below is a screenshot of the output. Note that the secret word may or may not be in caps depending on how you approach the problem.
  11.  
  12. Picture of code that shows the missed and guessed letters in all caps.
  13. There are several ways to accomplish this. You should definitely try and figure out how to do this on your own, but if you are still stuck even after giving it you best effort then click here for a hint.
  14.  
  15. Lesson 3
  16. For this part of the lab project, modify the code so that each of the missed letters has a separator in between them. You can choose any separator you would like. The example below uses a comma.
  17.  
  18. Picture of code that shows a comma in between each incorrectly guessed letter.
  19. There probably aren’t as many ways to do this as the previous project, but you should try and figure out a way on your own. If you are still stuck even after giving it you best effort then click here for a hint.
  20.  
  21. Lesson 4
  22. Below is the Dictionary code snippet for the Chapter 9 ½ Hangman extended code. For the last part of this lab project you will need to modify the list in the Hangman in the code so that it is a dictionary instead of list.
  23.  
  24. Here is the dictionary word list that should be inserted in place of the original secret word list.
  25. "words={
  26. 'Colors':'red orange yellow green blue indigo violet white black brown'.split(),
  27. 'Shapes':'square triangle rectangle circle ellipse rhombus trapezoid chevron pentagon hexagon septagon octagon'.split(),
  28. 'Fruits':'apple orange lemon lime pear watermelon grape grapefruit cherry banana cantaloupe mango strawberry tomato'.split(),
  29. 'Animals':'bat bear beaver cat cougar crab deer dog donkey duck eagle fish frog goat leech lion lizard monkey moose mouse otter owl panda python rabbit rat shark sheep skunk squid tiger turkey turtle weasel whale wolf wombat zebra'.split()}
  30. Next, you should capture the function below and insert it in the Hangman code.
  31. def getRandomWord(wordDict):
  32. # This function returns a random string from the passed dictionary of lists of strings, and the key also.
  33. # First, randomly select a key from the dictionary:
  34. wordKey = random.choice(list(wordDict.keys()))
  35. # Second, randomly select a word from the key's list in the dictionary:
  36. wordIndex = random.randint(0, len(wordDict[wordKey]) - 1)
  37. return [wordDict[wordKey][wordIndex], wordKey]
  38. Instead of returning the string wordList[wordIndex], the new function returns a list with two items. The first item is wordDict[wordKey][wordIndex]. The second item is wordKey.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement