PROBLEM 1 Write a hangman program called hangman.py.  Modify your program so that the following functionality is added: Instead of selecting the word from a hard coded list, read input from a file containing a list of words (File: kangaroo, capybara, wombat, koala, wallaby, quokka, platypus, dingo, kookaburra) and store the data (strings) in a list Hint: try using the readline() function or a for loop randomly select a string from the list output / write the selected string to a new file   when the game ends, the following information should be outputted to a new file: ●  the word ●  the state of the hangman ●  if the user won or lost Example outputs: quokka  O \ |   | You won! kangaroo  O \ | /   | /    \ You lost!   Afterwards,  The following changes should be made to the program: read in a file one line at a time (same as before so far), but instead of simply adding each item to the list, split the string at ‘:’ (.split(“:”)) and add the first string (post-split) as the key and the second string as the value. The key in the dictionary is the word and the value is a hint. if the user enters ‘hint’ (case insensitive) then the hint associated with the word (the value associated with the randomly selected key) should be printed The program should function much the same with just those two changes. This will require adjusting how the word is selected since it is now stored in a dictionary, not a list, adjusting the input filter function to accommodate user input 'hint', adding a function that prints the hint, and adjusting how the data from the file is processed/manipulated. Hint: to randomly select from a dictionary, there are a few different approaches you can take, just remember that to access values in a dictionary you use .get(key) or dictionary[key]. A couple of suggestions might be to also store a list just of the keys, randomly select one of them, and then use the selected word from the list as a reference. However, this requires storing a whole other list, maybe you can think of a more space-efficient way of randomly selecting a key.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

PROBLEM 1

Write a hangman program called hangman.py. 

Modify your program so that the following functionality is added:

  1. Instead of selecting the word from a hard coded list,

    • read input from a file containing a list of words (File: kangaroo, capybara, wombat, koala, wallaby, quokka, platypus, dingo, kookaburra) and store the data (strings) in a list

      Hint: try using the readline() function or a for loop

    • randomly select a string from the list

    • output / write the selected string to a new file

     

  2. when the game ends, the following information should be outputted to a new file:

●  the word

●  the state of the hangman

●  if the user won or lost

Example outputs:

quokka

 O

\ |

  |

You won!

kangaroo

 O

\ | /

  |

/    \

You lost!

 

Afterwards, 

The following changes should be made to the program:

  1. read in a file one line at a time (same as before so far), but instead of simply adding each item to the list, split the string at ‘:’ (.split(“:”)) and add the first string (post-split) as the key and the second string as the value. The key in the dictionary is the word and the value is a hint.

  2. if the user enters ‘hint’ (case insensitive) then the hint associated with the word (the value associated with the randomly selected key) should be printed

The program should function much the same with just those two changes.

This will require adjusting how the word is selected since it is now stored in a dictionary, not a list, adjusting the input filter function to accommodate user input 'hint', adding a function that prints the hint, and adjusting how the data from the file is processed/manipulated.

Hint: to randomly select from a dictionary, there are a few different approaches you can take, just remember that to access values in a dictionary you use .get(key) or dictionary[key]. A couple of suggestions might be to also store a list just of the keys, randomly select one of them, and then use the selected word from the list as a reference. However, this requires storing a whole other list, maybe you can think of a more space-efficient way of randomly selecting a key.

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 7 images

Blurred answer
Knowledge Booster
Lists
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education