Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions 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
Check Mark
Knowledge Booster
Background pattern image
Computer Science
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
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education