Python count lines containing keyword in txt file returns 0

3 days ago 12
ARTICLE AD BOX

I'm trying to count the number of lines in a text.txt file that contain the keyword "Python", but my code always returns 0 even though I know the file has lines with "Python".

python version:3.11.9

Here's my code:

count = 0 file = open("text.txt", "r") for line in file: if "Python" in file: count += 1 print(count) file.close()

Why is the count always 0? Where's the mistake in my code?

Read Entire Article