Question

HINT: USE def count_letters function: DO NOT use Length Function!!!!!!!!!!!!!!!!!!!!!!!! use string format to display percentage....

HINT:

USE def count_letters function:

DO NOT use Length Function!!!!!!!!!!!!!!!!!!!!!!!!

use string format to display percentage. "{:.1f}".format

DO NOT USE ROUND

PYTHON:

  1. Develop a program that asks the user to enter a text. The program should analyze the text and print out unique letters, in alphabetical order, with the percentage information of each letter. Case should be ignored. Write a function to analyze the text string. No global variables are used in the function. Function parameters must be used.

    Hint: You can convert all letters into lowercase before processing.

    A sample run of the program might look this. Show one decimal place percentage:

Please enter a sentence: This is String

g 8.3%
h 8.3%
i 25.0%

n 8.3%
r 8.3%

s 25.0%

t 16.7%

HINT:

USE def count_letters function:

DO NOT use length function!!!!!!!!!!!!!!!!!!!!!!!!

use string format to display percentage. "{:.1f}".format

DO NOT USE ROUND

THANK YOU FOR YOUR HELP

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

Please see the screenshot of the CODE for proper indentation. Otherwise, you might get errors.

There is code with comments after the screenshots.

Please feel free to ask any doubts and give feedback!

Output:

Screenshot of the code:

CODE:

def count_letters(s):

#result dictionary

d={}

#for every character i in string s

for i in s:

#if i is not alphabet, ignore it

if i.isalpha()==False:

continue

#add the character to result if it is not present, increment by 1 if its already present

if i in d:

d[i]+=1

else:

d[i]=1

#reutn the result

return d

#take input

s=input("Please enter a sentence: ")

#convert to lower case

s=s.lower()

#count letters using the above function

d=count_letters(s)

#total count=0

total=0

#get the total number of letters in the senetence

for i in d:

total+=d[i]

#for every letter in keys of count dictionry(sortted order)

for i in sorted(d.keys()):

#print the percentage, using {:.1f} format

print(i+" {:.1f}".format((d[i]/total)*100))

Add a comment
Know the answer?
Add Answer to:
HINT: USE def count_letters function: DO NOT use Length Function!!!!!!!!!!!!!!!!!!!!!!!! use string format to display percentage....
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
  • The skeleton code (starter file) for the problem is pasted below: def phoneNumber(letters): result = ""...

    The skeleton code (starter file) for the problem is pasted below: def phoneNumber(letters): result = "" # ADD YOUR CODE HERE return result def loadEvents(filename): events = {} # ADD YOUR CODE HERE return events def timeline(events): # ADD YOUR CODE HERE return # DO NOT modify or remove the code below! We will use it for testing. if __name__ == "__main__": # Problem 1: Decoding Telephone Numbers ph = input("Enter the text to translate: ") print("The corresponding phone number...

  • Extra Credit Function Name: anagram Inputs: 1. 2. (char) String representing the anagram (char) Name of...

    Extra Credit Function Name: anagram Inputs: 1. 2. (char) String representing the anagram (char) Name of text file to write to Outputs: none File Outputs: 1. A text file containing all the permutations of the anagram Banned Functions: perms(), permute(), ipermute(), nchoosek (), combnk() Background: You guys know what do. You are professional MATLAB now, you got this! Function Description: Given a string, recursively determine all the unique ways to rearrange the letters. (i.e al the unique permutations). For example,...

  • Do in Python please provide screenshots aswell. Here are the requirements for your game: 1. The...

    Do in Python please provide screenshots aswell. Here are the requirements for your game: 1. The computer must select a word at random from the list of avail- able words that was provided in words.txt. The functions for loading the word list and selecting a random word have already been provided for you in ps3 hangman.py. 2. The game must be interactive; the flow of the game should go as follows: • At the start of the game, let the...

  • Write a javascript program which implements the following two classical cryptosystem which we covered in class:...

    Write a javascript program which implements the following two classical cryptosystem which we covered in class: Affine Cipher Vigenere Cipher Your program should consist of at least five functions: Two functions named encrypt, one for each of the two algorithms which accepts a lowercase alphabetical plaintext string and key as input and outputs a corresponding cipher text string. Two functions named decrypt, one for each of the two algorithms which accepts a lowercase alphabetical ciphertext string and a key as...

  • Hint: generating function You are trying to design a string that must be length x. You...

    Hint: generating function You are trying to design a string that must be length x. You can only use these letters however: n,m,0,p. There are some other rules that you must follow: n can show up odd times m can show up even times o can show up any number of times p can show up in a multiple of 4 times How many ways strings of length x can be made? (Answer will be in terms of x)

  • Please note that I cannot use the string library function and that it must be coded...

    Please note that I cannot use the string library function and that it must be coded in C89, thank you! Formatting: Make sure that you follow the precise recommendations for the output content and formatting: for example, do not change the text in the first problem from “Please enter a string of maximum 30 characters:” to “Enter string: ”. Your assignment will be auto-graded and any changes in formatting will result in a loss in the grade. 2.Comments: Header comments...

  • Write a Java Program that performs the following functionalities: and you can use if statements, cases,...

    Write a Java Program that performs the following functionalities: and you can use if statements, cases, and string methods Enter a new main sentence Find a String Find all incidents of a String Find and Replace a String Replace all the incidents of a String Count the number of words Count a letter’s occurrences Count the total number of letters Delete all the occurrences of a word Exit The program will display a menu with each option above, and then...

  • Palindrome Detector C++ A palindrome is any word, phrase, or sentence that reads the same forward...

    Palindrome Detector C++ A palindrome is any word, phrase, or sentence that reads the same forward and backward. Here are some well-known palindromes: Able was I, ere I saw Elba A man, a plan, a canal, Panama Desserts, I stressed Kayak Write a program that determine whether an input string is a palindrome or not. Input: The program should prompt the user "Please enter a string to test for palindrome or type QUIT to exit: " and then wait for...

  • C Code Create a tool in which a user can enter a string (up to 25...

    C Code Create a tool in which a user can enter a string (up to 25 characters) and choose how they wish to manipulate the string from a menu your program will display (see the run-through). The program will continue to ask for commands until the user enters the “quit” command. The commands are: • “Replace All” If a user types “replace all” using ANY sort of capitalization, your program will prompt the user to enter the character to change...

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