Question: Complete the create_frequency_chart_file() function that takes a single list parameter - letter_frequencies. The items in this list are tuples. Each tuple contains two items:
Complete the create_frequency_chart_file() function that takes a single list parameter - letter_frequencies. The items in this list are tuples. Each tuple contains two items: the first item is a string representing an alphabetical letter and the second item is an integer representing the letter frequency (how many times it appears in a certain text). You can assume that all letters in the tuples are in lowercase and that the tuples are arranged in the list in alphabetical order. The function should write, to a text file, a vertical bar chart representing the letter frequencies. Each bar in the chart is made up of "#" characters, the number of which correspond to the letter frequency. The letters are displayed at the base of the bar chart. Note that only letters with a frequency greater than 0 are included in the bar chart. The filename of the text file is XXX.txt where XXX represents your own username (upi). Some examples of the function being called are shown below. Note: Remember to close the file. You can assume that the parameter list is not empty. The print_contents () function is used for marking purposes. You can assume that it is given in CodeRunner. Implementing helper functions may help simplify your solution. For example: Test letter_frequencies = [('a', 16), ('b', 1), ('c', 6), ('d', 10), ('e', 18), ('f', 3), ('g', 8), ('h', 14), ('1', 13), ('j', 0), ('k', 1), ('l', 4), ('m', 4), ('n', 15), ('o', 12), ('p', 6), ('q', 0), ('r', 10), ('s', 10), ('t', 8), ('u', 2), ('v', 2), ('w', 6), ('x', 0), ('y', 5), ('z', 0)] create_frequency_chart_file(letter_frequencies) print contents('bsin470.txt') letter_frequencies = [('a', 5), ('b', 2), ('c', 1), ('d', 2), ('e', 10), ('f', 5), ('g', 5), ('h', 7), ('i', 5), ('j', 0), ('k', 0), ('l', 3), ('m', 5), ('n', 5), ('o', 5), ('p', 0), ('q', 0), ('r', 10), ('s', 3), ('t', 11), ('u', 3), ('v', 0), ('w', 1), ('x', 0), ('y', 6), ('z', 0)] create frequency_chart_file (letter_frequencies) print contents('bsin470.txt') Result # # # # # # # # # # # # # # ## ## # ## # ## ### # ## ### # ### ### # ### ### # ### ### ######## # ####### ######## ## ## # # # # ## ## ## # # # # # # # ## ## ## ## # # ## ## ### ## ## ### ###### # ###### # ####### ############ ###################### abcdefghiklmnoprstuvwy ## # # # # # # # ## # # # # # ##### #### # # ##### #### # # ############# # ## ############## # ################### abcdefghilmnors tuwy Test X letter_frequencies ('h', 14), ('i', 13), ('j', 0), = [('a', 16), ('b', 1), ('c', 6), ('d', 10), ('e', 18), ('f', 3), ('g', 8), ('k', 1), ('l', 4), ('m', 4), ('n', 15), ('0', 12), ('p', 6), ('q', 0), ('r', 10), ('s', 10), ('t', 8), ('u', 2), ('v', 2), ('w', 6), ('x', 0), ('y', 5), ('z', 0)] create_frequency_chart_file (letter_frequencies) print contents('bsin470.txt') Expected # # # # # # # # # # # # # # ## # ## # # ## ## ## ## ## ## ### # ## ### # ### ### # ### ### # # # ## ## ## ## ## ## ### ## ## ### ###### # ###### ## ## ## ######## ### ### # ######## ####### # ############ ####### # ###################### abcdefghiklmnoprstuvwy Got ***Run error*** Traceback (most recent call last): File "_tester_.python3", line 42, in print_contents('bsin470. txt') File "_tester_.python3", line 3, in print_contents with open (filename, 'r') as input file: FileNotFoundError: [Errno 2] No such file or directory: 'bsin470.txt' X
Step by Step Solution
3.40 Rating (153 Votes )
There are 3 Steps involved in it
Answer def createfrequencychartfileletterfrequencies Define the filename ... View full answer
Get step-by-step solutions from verified subject matter experts
