Ask your own question, for FREE!
Computer Science 65 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!
Latest Questions
luhsky25: who fears God
27 minutes ago 0 Replies 0 Medals
luhsky25: i came up from hitting licks
1 hour ago 3 Replies 1 Medal
whyjustwhy: guys my art is amazing
50 minutes ago 10 Replies 2 Medals
luhsky25: rate my moms favorite song
2 hours ago 5 Replies 0 Medals
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!