guys i m trying to make a program which gives the percentage of each letter in a word...but its not working as expected.. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

guys i m trying to make a program which gives the percentage of each letter in a word...but its not working as expected..

https://code.sololearn.com/cxNgJM29CD8z/?ref=app

3rd May 2020, 1:30 PM
PRO
PRO - avatar
3 Answers
+ 1
You have stored only capital letters I.e. Alphabets=['A','B'.....'Z'] And the word you passed in the function call contains small letters also...so you are getting output only for capital letters
3rd May 2020, 2:03 PM
ANJALI SAHU
+ 1
So for your desired output.. You can convert the string into uppercase..I.e word.upper()
3rd May 2020, 2:04 PM
ANJALI SAHU
+ 1
Or you can take help of this code def per(word,letter): count=0 for i in word: if i==letter: count+=1 p=(count/len(word))*100 print( letter,"percentage ",p) word="pill" print(word) for letter in word: per(word,letter)
3rd May 2020, 2:04 PM
ANJALI SAHU