Write a program which reads the string


Write a program which reads the string:
"My country tis of thee, Sweet land of liberty, Of thee I sing."
and determines the frequencies of each letter of the alphabet by using a list as your counters (freq = 26*[0], here all the 26 elements of freq are set to zero). Here are steps you may want to follow. 

In the main() method assign the string to s and send s to method parse(s). 
In parse(s) 
Zero the elements of freq (i.e., freq = 26*[0]). 
Calls function upcase(c) that converts a lowercase letter in s to an uppercase one and leaves other characters alone. Use capitol.py of March 23 as a model for upcase(c). The function upcase(c) should be called for each character in s. 
If the converted character is an uppercase letter, increment the proper element of freq. Do this by converting an uppercase letter to the int num such that for 'A', num becomes 0; for 'B', it becomes 1, etc. Use ord() to do this. So if an 'A' is encountered, freq[0] = freq[0] + 1; if a 'B' is encountered, freq[1] = freq[1] + 1, and in general for the num'th letter, freq[num] = freq[num] + 1 
Use freq as a parameter to call function histo(freq). 
Use histo2.py of MAR 23 as a guide to writing function histo(freq) 
Of the functions described, only upcase() has a return statement. 

The results look like: 
Histogram of letter frequencies
number of A's is 1:A
number of B's is 1:B
number of C's is 1:C
number of D's is 1:D
number of E's is 7:EEEEEEE
number of F's is 3:FFF
number of G's is 1:G
number of H's is 2:HH
number of I's is 4:IIII
number of J's is 0:
number of K's is 0:
number of L's is 2:LL
number of M's is 1:M
number of N's is 3:NNN
number of O's is 4:OOOO
number of P's is 0:
number of Q's is 0:
number of R's is 2:RR
number of S's is 3:SSS
number of T's is 6:TTTTTT
number of U's is 1:U
number of V's is 0:
number of W's is 1:W
number of X's is 0:
number of Y's is 3:YYY
number of Z's is 0:


You may want to eliminate printing those letters with zero frequencies in the string.

Request for Solution File

Ask an Expert for Answer!!
Programming Languages: Write a program which reads the string
Reference No:- TGS0131980

Expected delivery within 24 Hours