Home > Software engineering >  Why the count always equal to the word length here even if the condition is wrong?
Why the count always equal to the word length here even if the condition is wrong?

Time:09-10

word = input('Enter a word\n')
letter = input('Enter a letter\n')
count = 0
for letter in word:
    if letter == word[count] :
        count = count   1
print(count)

I am trying to count how many times the letter appear in the word. But somehow the count value always equal to the length of the word?

eg. word = try letter = y

the count should be 1 right? but the result is showing 3? I don't understand where the problem is..

  • Related