0

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.

19th May 2021, 1:02 PM
Nandita Balaji
Nandita Balaji - avatar
3 odpowiedzi
+ 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
19th May 2021, 1:14 PM
Lothar
Lothar - avatar
+ 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)
19th May 2021, 1:14 PM
sarada lakshmi
sarada lakshmi - avatar
0
len(letter) is always 1. You have to count letters inside "text"
19th May 2021, 1:08 PM
Michal Doruch