+ 2
Hi everyone
This is my question in python Given a string as input, you need to output how many times each letter appears in the string. You decide to store the data in a dictionary, with the letters as the keys, and the corresponding counts as the values. Create a program to take a string as input and output a dictionary, which represents the letter count. Sample Input hello Sample Output {'h': 1, 'e': 1, 'l': 2, 'o': 1} And I answer like this text = input() dict ={} #your code goes here for e in text: dict [e]= text.counts(e) print(dict) After run I have a string attributed error How can I fix it?
3 ответов
+ 4
Sharareh heyati
you added an 's' in count.
text.counts(e)
it should be :
text = input()
dict ={}
for e in text:
dict[e] = text.count(e)
print(dict)
+ 1
ThanksBob_Li 😬👌
0
oh