0

a=str(input()) b=str(input('letter_')) c=len(a) d=a.count(b) e=d/c f=e*100 print(int(f))

Is it a correct code for frequency of a letter in a word

31st Aug 2021, 3:09 PM
abiram sakthivel
abiram sakthivel - avatar
5 Respostas
0
def char_frequency(word): dict = {} for n in word: keys = dict.keys() if n in keys: dict[n] += 1 else: dict[n] = 1 return dict You can use this for character frequency
31st Aug 2021, 3:27 PM
Brain & Bones
Brain & Bones - avatar
+ 3
abiram sakthivel , do you need to know just how often a certain letter appears in a string, or do you need to know the frequency of all letters that occur in the string?
31st Aug 2021, 3:35 PM
Lothar
Lothar - avatar
+ 1
Hi abiram! Of course, your code is correct. But problem is that you have to print the exact output what is expected by Sololearn. Your code has a input prompt message. It's main reason that you're unable to pass in this practice. You can just remove the prompt message and check it again. Here it is my solution for this practice. text = input() l = input() print(int(text.count(l)/len(text)*100))
31st Aug 2021, 3:50 PM
Python Learner
Python Learner - avatar
0
Brain & Bones ur code has been failed in sololearn but in pudroid it is crt
31st Aug 2021, 3:32 PM
abiram sakthivel
abiram sakthivel - avatar
31st Aug 2021, 3:50 PM
Brain & Bones
Brain & Bones - avatar