I am working on a code for the tutorial. The code reads in a file input.txt
, and checks each line to see whether the letters in the line can be used to make the word "aardvark" (Uppercase letters can be used as well).
Here is my code:
with open("input.txt", "r") as text:
for w in text:
a = w.count('a')
r = w.count('r')
d = w.count('d')
v = w.count('v')
k = w.count('k')
if a >= 3 and r >= 2 and d >= 1 and v >= 1 and k >= 1:
print("Aardvark on line", w)
Here is my file:
No aardv*rks here!
Only armadillos and anteaters.
Animals are run down: very awful road kill.
I prefer a quick guacamole made from avocados.
The code printed out:
Aardvark on line Animals are run down: very awful road kill.
Aardvark on line I prefer a quick guacamole made from avocados.
The code worked fine, but I want to print out the line number instead of the line it self. Here is how I want to print out:
Aardvark on line 3
Aardvark on line 4
How do I do it?