Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+3 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 old_CSC201 by (1 point)

1 Answer

+1 vote

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 (1 point)
...