python - Letter count program -


in letter counting function, when use code

 collections import counter import string pickedletter= () count = 0 word = ()   def count_letters(word):     global count     wordslist = word.split()     words in wordslist:         if words == pickedletter:             count = count+1     return count  word = input("what want type? ") pickedletter = input("what letter want pick? ") print (count_letters(word)) 

i amount of letter 0, no matter what. example, here got in command prompt

what want type? rht letter want pick? r 0 >>> 

how fix how many times letter appears in string?

there's method counts number of occurrences of character. case insensitive, use string.lower()

print (word.count(pickedletter)) 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -