
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.

Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 7 images

- python LAB: Subtracting list elements from max When analyzing data sets, such as data for human heights or for human weights, a common step is to adjust the data. This can be done by normalizing to values between 0 and 1, or throwing away outliers. Write a program that adjusts a list of values by subtracting each value from the maximum value in the list. The input begins with an integer indicating the number of integers that follow.arrow_forwardPython code easy way plsarrow_forwardUsing c++ Contact list: Binary Search A contact list is a place where you can store a specific contact with other associated information such as a phone number, email address, birthday, etc. Write a program that first takes as input an integer N that represents the number of word pairs in the list to follow. Word pairs consist of a name and a phone number (both strings). That list is followed by a name, and your program should output the phone number associated with that name. Define and call the following function. The return value of FindContact is the index of the contact with the provided contact name. If the name is not found, the function should return -1 This function should use binary search. Modify the algorithm to output the count of how many comparisons using == with the contactName were performed during the search, before it returns the index (or -1). int FindContact(ContactInfo contacts[], int size, string contactName) Ex: If the input is: 3 Frank 867-5309 Joe…arrow_forward
- PYTHON Complete the function below, which takes two arguments: data: a list of tweets search_words: a list of search phrases The function should, for each tweet in data, check whether that tweet uses any of the words in the list search_words. If it does, we keep the tweet. If it does not, we ignore the tweet. data = ['ZOOM earnings for Q1 are up 5%', 'Subscriptions at ZOOM have risen to all-time highs, boosting sales', "Got a new Mazda, ZOOM ZOOM Y'ALL!", 'I hate getting up at 8am FOR A STUPID ZOOM MEETING', 'ZOOM execs hint at a decline in earnings following a capital expansion program'] Hint: Consider the example_function below. It takes a list of numbers in numbers and keeps only those that appear in search_numbers. def example_function(numbers, search_numbers): keep = [] for number in numbers: if number in search_numbers(): keep.append(number) return keep def search_words(data, search_words):arrow_forwardPYTHON!!! Write a function that will filter course grades that are stored in a list, creating and returning a new list. Your implementation must have the following rules: - The function must accept two (and only two) parameters: The first is: the maximum integer value for any grade to remain in the list (any value above the maximum will be filtered and removed from the list). The second is: the list of grades (you can assume the list contains only integer values) - The function must return a new list and not modify the existing list. - The function must use a list comprehension to filter the existing list and create the new list that is returned. - DO NOT USE THE: built-in-"filter" function.arrow_forwardThe next part of the program reads the file one line at a time and adds the scores, as a floating point numbers, to the list scores. scores = [] # empty list of scores for line in infile: line = line.strip() print (scores) # get score #convert to float # add to list of scores In the space below, complete the program fragment so that it prints the list of floating point scores as follows: [98.5, 97.4, 99.1, 97.2]arrow_forward
- Lin in out 1283.arrow_forwardplease write in python , thank u.arrow_forwardAssume, you have been given two lists: List_one and List_two. [Your program should work for any two given lists; change the following lists and check whether your program works correctly for the code you have written] Write a Python program that prints "True", if the given two lists have at least one common member. Otherwise, print "False". Hint: use a boolean variable as a flag to indicate if the two lists have at least one common element. Use break to end the loop when seeing a commom element. =================================================================== Given lists 1:List_one : [1, 4, 3, 2, 6]List_two : [5, 6, 9, 8, 7] Sample Output 1:True =================================================================== Given lists 2:List_one : [1, 4, 3, 2, 5]List_two : [8, 7, 6, 9] Sample Output 2:False #assign the boolean result (True/False) to variable "common_ele" (flag). def task5(list_1, list_2): # YOUR CODE HERE return common_ele Expert Solutionarrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





