0
Help with code python
I took this code from a lesson and changed the letters from a single letter to the whole alphabet in hopes if you entered a word or words you would get the amount of letters in that word So if someone put in âtheâ it would show the number 3 as in 3 letters but it just shows the number 0 https://code.sololearn.com/cfXh1PK9oTG3/?ref=app
6 Answers
+ 5
assuming that you are going to count the total number of lower case plus upper case letters. instead of a string with all these letters we can also use the string method .isalpha() together with variable 'x' in the for loop.
it returns True for all lower and upper case letters, but not for spaces, numbers or special characters. at the end of the iteration the variable 'count' holds the total number of letters.
hint: what we do not need in the input procedure is the converting of the input to string data format, because input returns everything as string by default.
this would be ok: text = input()
all the rest of your code can remain as it is.
+ 4
jellybeannugget
That's because x == a complete alphabet, so only a complete alphabet will return a True result aÄșlowing a count.
You could do something similar to your concept using a dictionary, where the keys are the letters and the values are set to 0.
Then as you iterate through your string, you could increment the value of the corresponding key.
+ 3
Besides Cristian Baeza Jimenez answer, also remove spaces and commas - I understand you want to count only letters.
+ 2
Rik Wittkopp thanks man helps alot
+ 2
Change the == for in and it will work
+ 1