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.
3 Respuestas
+ 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"