Welcome to the CSC Q&A.
Get help and give help!
Write great code!
It is our choices... that show what we truly are, far more than our abilities.

Categories

0 votes

Howdy! My code is accurate and displaying properly, it just skips the even-numbered lines of code from the in-file. I'm using the infile.readline() within the for loop, but I can't see where the code is going wrong.

asked in CSC201 by (108 points)

1 Answer

0 votes

From the posted File slides, since every line of our file has the data organized in exactly the same way, I would use the strategy on slide 32. That code kind of a Python short-cut for reading through the file line by line. You don't actually see the readline method, but each time through the loop the readline method is implicitly called and the next line of the file is stored in the loop control variable (ie. the one between for and in which in my slide is the variable line).

If you also use infile.readline() within the loop, then that statement reads another line from the file.

Each time through the for loop, you are reading in two lines from the file, but only processing the data from one of them.

answered by (4.2k points)
...