Question

Write a python program that will create a histogram of the number of times each character occurs in a file. Check https://en.wikipedia.org/wiki/Histogram and http://interactivepython.org/runestone/static/thinkcspy/Functions/ATurtleBarChart.html for help. Your program will read any input text file and print the histogram. If you have a huge file you should have a graph similar to:

0.14 012 0.1 008 0.06 0.04 0.02

Note the y-axis shows the percentage of each letter. The height of each bar is percentage of that letter. Program MUST show the graph with percentage marks on y-axis and letters on the x-axis as shown in the graph below. THE GRAPH MUST HAVE THE TICK MARKS AND LABELS ON Y AND X AXES. Please don't answer if you can't do that, this is my third time asking this question on here. Matplotlib and any other external plotting libraries can't be used, only the python turtle to draw.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

# Python3 code to demonstrate
# each occurrence frequency using
# naive method

# initializing string
test_str = "GeeksforGeeks"

# using naive method to get count
# of each element in string
all_freq = {}

for i in test_str:
   if i in all_freq:
       all_freq[i] += 1
   else:
       all_freq[i] = 1

# printing result
print ("Count of all characters in GeeksforGeeks is :\n "
                                       + str(all_freq))

# Python3 code to demonstrate
# each occurrence frequency using
# collections.Counter()
from collections import Counter

# initializing string
test_str = "GeeksforGeeks"

# using collections.Counter() to get
# count of each element in string
res = Counter(test_str)

# printing result
print ("Count of all characters in GeeksforGeeks is :\n "
                                       + str(res))

# Python3 code to demonstrate
# each occurrence frequency using
# dict.get()

# initializing string
test_str = "GeeksforGeeks"

# using dict.get() to get count
# of each element in string
res = {}

for keys in test_str:
   res[keys] = res.get(keys, 0) + 1

# printing result
print ("Count of all characters in GeeksforGeeks is : \n"
                                           + str(res))

# Python3 code to demonstrate
# each occurrence frequency using
# set() + count()

# initializing string
test_str = "GeeksforGeeks"

# using set() + count() to get count
# of each element in string
res = {i : test_str.count(i) for i in set(test_str)}

# printing result
print ("The count of all characters in GeeksforGeeks is :\n "
                                           + str(res))

Add a comment
Know the answer?
Add Answer to:
Write a python program that will create a histogram of the number of times each character occurs ...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a structured (procedural) Python program that solves the following spec: Soundex System Coding: Soundex is...

    Write a structured (procedural) Python program that solves the following spec: Soundex System Coding: Soundex is a system that encodes a word into a letter followed by three numbers that roughly describe how the word sounds. Therefore, similar sounding words have the same four-character code. Use the following set of (slightly modified #4) rules to create a translator from English words to Soundex Code: Retain the first letter of the word. For letters 2 …n, delete any/all occurrences of the...

  • 1. Expense Pie Chart Create a text file that contains your expenses for last month in...

    1. Expense Pie Chart Create a text file that contains your expenses for last month in the following categories: -Rent -Gas -Food -Clothing -Car Payment -Misc Write a Python program that reads the data from the file and uses matplotlib to plot a pie chart showing you how you spend your money. 2. 1994 weekly gas graph The text file named 1994_Weekly_Gas_Averages.txt contains the average gas price for each week in the year 1994. (There are 52 lines in the...

  • You will create a PYTHON program for Tic-Tac-Toe game. Tic-Tac-Toe is normally played with two people....

    You will create a PYTHON program for Tic-Tac-Toe game. Tic-Tac-Toe is normally played with two people. One player is X and the other player is O. Players take turns placing their X or O. If a player gets three of his/her marks on the board in a row, column, or diagonal, he/she wins. When the board fills up with neither player winning, the game ends in a draw 1) Player 1 VS Player 2: Two players are playing the game...

  • for future views please dont use it for spring 2020 Write a Perl program to accomplish...

    for future views please dont use it for spring 2020 Write a Perl program to accomplish each of the following on the file solar.txt (see link at the class homepage) 1. Print all records that do not list a discoverer in the eighth field. 2. Print every record after erasing the second field. Note: It would be better to say "print every record" omitting the second field . 3. Print the records for satellites that have negative orbital periods. (A...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT