Ask your own question, for FREE!
Computer Science 40 Online
Gucchi:

programming help

Gucchi:

1 attachment
Gucchi:

am i right with D?

Gucchi:

@extrinix

Gucchi:

if u can help

Extrinix:

It depends on your situation. If you count the amount of lines using a function before you loop through the files, it would be a `while` loop. But in this case, you're looping through `each line` without knowing the exact number of lines you have. For this, I would use a `for` loop instead of a `while`, as a `for` loop stops whenever the last line is reached.

Extrinix:

Such in that, a while loop would look as follows: ```python file = open("file.txt", "r") lineCount = file.readlines() # while loop and a counter associated with lineCount would go here ``` and a for loo would look as such: ```python file = open("file.txt", "r") # for loop would go here, no need for a counter unless it's needed in file data ```

Extrinix:

loop* smh

Gucchi:

okay i get it finally

Gucchi:

thanks so much bro

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!