Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

On Python 3.6, write a function char_table(s), where s is a string. The function

ID: 3591186 • Letter: O

Question

On Python 3.6, write a function char_table(s), where s is a string. The function should produce a table that shows the characters in the string and the number of occurrences of each character. Make the table nicely formatted, using right justification for the numbers (check out the format command.). List the characters in order (the order in the character encoding). Give some examples of the output. On Python 3.6, write a function char_table(s), where s is a string. The function should produce a table that shows the characters in the string and the number of occurrences of each character. Make the table nicely formatted, using right justification for the numbers (check out the format command.). List the characters in order (the order in the character encoding). Give some examples of the output.

Explanation / Answer

def char_table(s):
    chars = []
    for i in range(0,len(s)):
        if s[i] not in chars:
            chars.append(s[i])
    chars.remove(' ')
    chars.sort()
  

    print("Sr.No Character Count")
  

    for i in range(0,len(chars)):
        print("%5d%10s%7d "% (i+1,chars[i], s.count(chars[i])))


char_table("sun at the zenith greening earth")

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote