I have tried writting a function that takes a string of characters and returns the number of words in Enlgish that do not contain any of the characters in the string.
op= open('words.txt')
def avoids(forbidden):
"""counts the number of words in Enlgish which do not contain any
character found in forbidden str"""
number=0
for line in op:
count=0
for letter in line.strip():
if forbidden.count(letter)==0:
count=count+1
if count==len(line.strip()):
number=number+1
return number
print(avoids('e'))
print(avoids('a'))
When running the program, print(avoids('e'))
works fine, printing 37641; however, print(avoids('a'))
prints 0. Regardless of the strings I put as arguments in the function calls, the first funtion always returns the correct value, while the second one always returns 0.
I am new to coding so I don't know why this happens and how to solve it. Help please.