Jan-29-2018, 12:28 AM
This is the assignment:
There are aardvarks on the loose! We need you to check whether there are any aardvarks hidden in a text file.
To start, your program should read in a file input.txt, one line at a time, numbering the lines from 1. You should check 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. So, if the file input.txt contains this:
No aardv*rks here!
Only armadillos and anteaters.
Animals are run down: very awful road kill.
I prefer a quick guacamole made from avocados.
then your program should output:
If you check carefully, you should be able to see why.
If aardvark can be spelt out on each line with the letters provided in any order, the program should say so.
This is what I have done so far:
I have tried moving the function of line 25-26 to line 12 but that still is not changing anything.
Please help.
There are aardvarks on the loose! We need you to check whether there are any aardvarks hidden in a text file.
To start, your program should read in a file input.txt, one line at a time, numbering the lines from 1. You should check 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. So, if the file input.txt contains this:
No aardv*rks here!
Only armadillos and anteaters.
Animals are run down: very awful road kill.
I prefer a quick guacamole made from avocados.
then your program should output:
Output:Aardvark on line 3
Aardvark on line 4
If you check carefully, you should be able to see why.
If aardvark can be spelt out on each line with the letters provided in any order, the program should say so.
This is what I have done so far:
lines=[] f = open('input.txt') line = f.readline() x=0 while line: x=x+1 if line.count('a')==3: if line.count('r')==2: if line.count('d')==1: if line.count('v')==1: if line.count('k')==1: lines.append(x) else: line = f.readline() else: line = f.readline() else: line = f.readline() else: line = f.readline() else: line = f.readline() for i in lines: print('Aardvark on line',i)My output is blank because it is not printing anything.
I have tried moving the function of line 25-26 to line 12 but that still is not changing anything.
Please help.