Question

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

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.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

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")

Add a comment
Know the answer?
Add Answer to:
On Python 3.6, write a function char_table(s), where s is a string. The function should produce...
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
  • Python File Compression: Write a function called “compressString” which compresses a string such that any consecutive...

    Python File Compression: Write a function called “compressString” which compresses a string such that any consecutive repeated characters are replaced with one of the character and the number of times the character is repeated. This is also known as "Run length encoding". Examples:“aaabbc” -> “a3b2c”“abc” -> “abc”“aaqakkaccc” -> a2qak2a2c3

  • Python Function Name: unscramble Parameters: a string Returns: a string Description: Write a function, unscramble, that...

    Python Function Name: unscramble Parameters: a string Returns: a string Description: Write a function, unscramble, that takes an input string, and returns a the unscrambled version of the argument. To unscramble the string: When the string has an odd number of characters, middle character is the first character in the unscrambled result Pairs of remaining characters are added to the result, proceeding left to right from inner-most to outer-most characters. Example Call: unscramble('3cis1') Expected result: ics31 Example Call: unscramble('ocicssol') Expected...

  • 8.4 in python function that checks whether a string is a valid password. Suppose the pas...

    8.4 in python function that checks whether a string is a valid password. Suppose the pas rules are as follows: . A password must have at least eight characters - A password must consist of only letters and digits. ■ A password must contain at least two digits. Write a program that prompts the user to enter a password and displays valid password if the rules are followed or invalid password otherwise (Occurrences of a specified character) Write a function...

  • In python Exercise 4 (graded) Write a function "passValidate" that takes a string "s" and checks...

    In python Exercise 4 (graded) Write a function "passValidate" that takes a string "s" and checks the validity of string as a password Validation Rules: At least 1 lowercase letter between [a-z] and 1 upper case letter between [A-Z]. At least 1 number between [0-9 At least 1 character from [$#@]. Minimum length 6 characters. Maximum length 16 characters. CS103-Lab 13 Page 3 of 3 Sample Input: s"Uab@2762" Sample Output: True

  • #Write a function called check_formula. The check_formula #function should take as input one parameter, a string....

    #Write a function called check_formula. The check_formula #function should take as input one parameter, a string. It #should return True if the string holds a correctly #formatted arithmetic integer formula according to the rules #below, or False if it does not. # #For this problem, here are the rules that define a #correctly-formatted arithmetic string: # # - The only characters in the string should be digits or the five arithmetic operators: +, -, *, /, and =. Any other...

  • Write a Python function called more() that takes three string inputs and outputs a string Formally,...

    Write a Python function called more() that takes three string inputs and outputs a string Formally, the function signature and output are given by rucharist, char: str words str) > str Use the same names for the input arguments as shown above Note that charl and char2 will always be a string of length 1 (ie, it is a single character. The function checks which of charl or char2 appears more often in the word string and returns that character...

  • Write a Python function has_subsequence(a,s) that determines if the list (or string), a, contains s as...

    Write a Python function has_subsequence(a,s) that determines if the list (or string), a, contains s as a (not necessarily consecutive) subsequence. Examples 'here we go again' contains 'we gain' as a subsequence. 'green eggs and ham sandwhiches' contains 'reggae' as a subsequence. Your function should return an array of indices that shows the location of the elements of s in a. In the 'here we go again' example this array would contains [5,6,12,13,14,15]. If you can't find s as a...

  • 10. replaceSubstring Function Write a function named replaceSubstring. The function should accept three C-string or string...

    10. replaceSubstring Function Write a function named replaceSubstring. The function should accept three C-string or string object arguments. Let's call them string1, string2, and string3. It should search string for all occurrences of string2. When it finds an occurrence of Programming Challenges string2, it should replace it with string. For example, suppose the three arguments have the following values: stringt: "the dog jumped over the fence" string 2 "the" string3: "that" With these three arguments, the function would return a...

  • Write a python function that takes in a string to use as a prompt and shows...

    Write a python function that takes in a string to use as a prompt and shows it to the user. Then get input from the user. If they entered a single sign out of the set +,-,*,/,% return it. If they entered anything else, give them a warning: “You may only enter one of the characters: +- * /%” and then repeat until they enter a correct option.

  • Write a Python function make_triangle(trianglechar, triangleheight) that will return a string with an isosceles right triangle...

    Write a Python function make_triangle(trianglechar, triangleheight) that will return a string with an isosceles right triangle based on the two formal parameters triangle_height giving the triangle height and triangle_char that gives the symbol to be printed. Important notes: This program returns (not prints!) a string. For this function and the other part of this lab you are required to put in a docstring. That will be checked by a TA/grader reading the program. Every one of the occurrences of triangle_char...

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