letter frequency, python data structures | Sololearn: Learn to code for FREE!

+1

letter frequency, python data structures

You are making a program to analyze text. Take the text as the first input and a letter as the second input, and output the frequency of that letter in the text as a whole percentage. my input: text = input('') letter = input('') frequency = int((len(letter)/len(text))*100)thi print(frequency) Please tell me what is wrong.

5/19/2021 1:02:49 PM

Nandita Balaji

3 Answers

New Answer

+3

Nandita Balaji , it is much more simple than you can imagine. you can use a string function <count()> like: frequency = text.count(letter) <text> is your string input, and <letter> is your letter input

+1

len() returns the length of that particular string.. However, here you need the count of that character in the given text.. It goes smthg like this.. text = input() letter = input() frequency = int((text.count(letter)/len(text))*100) print(frequency)

0

len(letter) is always 1. You have to count letters inside "text"