Complete the create_frequency_chart_file() function that takes a single list parameter - letter_frequencies. The items in this...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 <module> 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 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 <module> 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
Expert Answer:
Answer rating: 100% (QA)
Answer def createfrequencychartfileletterfrequencies Define the filename ... View the full answer
Related Book For
Systems Analysis And Design
ISBN: 978-1119496489
7th Edition
Authors: Alan Dennis, Barbara Wixom, Roberta M. Roth
Posted Date:
Students also viewed these programming questions
-
Factor the given polynomial. 10x - 23x-5
-
Explain how family decision making may differ from the individual decision making process. What types of conflicts have you seen during the family decision making process, and what strategies have...
-
You are required to write a Python program that will manage character (heroes and villain) information. Character (hero and villain) information will be stored in a text file that will be read in...
-
Parker Associates purchased a patent in 2018 for $200,000. The patent will be amortized over 20 years. How would Parker adjust for the annual amortization for the patent on the balance sheet? Credit...
-
Sketch a rough graph of the outdoor temperature as a function of time during a typical spring day.
-
An ideal gas, C P = (7/2)R, is heated in a steady-flow heat exchanger from 70C to 190C by another stream of the same ideal gas which enters at 320C. The flow rates of the two streams are the same,...
-
The solar constant is defined as the average flux of solar energy incident on the outer fringes of the Earth's atmosphere and a commonly used value is \(1.353 \mathrm{~kW} / \mathrm{m}^{2}\). If the...
-
Tex Hardware sells many of its products overseas. The following are some selected transactions. 1. Tex sold electronic subassemblies to a firm in Denmark for 120,000 Danish kroner (Dkr) on June 6,...
-
1 . differentiate between data elements and data types 2 . distinguish among different types of modern databases 3 . explain how businesses identify risks and opportunities associated with emerging...
-
What are some of the arguments for and against using the term industrial relations to describe union management relationships?
-
Find the values of the VR and VR to have VR1 = 9VR2 + 4 mA E =20 V R R + VR + VR
-
Why have the courts refused to interpret the Second Amendments protection of the right to keep and bear arms to prohibit gun control legislation? On what bases other than the Second Amendment can one...
-
What factors do you think a defense attorney considers in deciding whether to advise a client to testify in his or her own behalf at trial?
-
Should plea bargaining be abolished? If not, what modifications might be necessary to protect (a) the defendant and (b) the public?
-
How has the nationalization of the criminal law that occurred through decisions of the U.S. Supreme Court during the 1960s and 1970s affected the appellate process?
-
Based on the ruling of the Supreme Court in City of Chicago v. Morales, what protections of the individual do you think must be included in an ordinance proscribing loitering?
-
https://myclass.ufv.ca/bbcswebdav/pid-1114410... https://myclass.ufv.ca/bbcswebdav/pid-108921... https://myclass 3. (6 points) What is the output? Explain your answer (Trace it) def something (str1,...
-
In July 2013, cnet.com listed the battery life (in hours) and luminous intensity (i. e., screen brightness, in cd/m2) for a sample of tablet computers. We want to know if screen brightness is...
-
Why would one use a decision tree and/or decision table in a process description?
-
Create a set of use cases for the following system: A Real Estate, Inc. (AREI), sells houses. People who want to sell their houses sign a contract with AREI and provide information on their house....
-
Draw a level 0 data flow diagram (DFD) for the video store system in Exercise F, Chapter 4.
-
The general expression for the conservation of any (conserved) quantity Q can be written in the form of Equation 1.12. We have said that dollars are also a conserved quantity, so Equation 1.12 should...
-
A dimensionless grouping of variables and parameters that are important in pipe flow is called the Reynolds number: where $V$ is the average velocity over the cross section in a pipe of diameter $D$...
-
Basic Concepts by considering the simple one-dimensional steady flow between two parallel plates, Figure 1.1. The area of each plate $A_{y}=1 \mathrm{~m}^{2}$ and the gap between the two plates is...
Study smarter with the SolutionInn App