Ask your own question, for FREE!
Computer Science 12 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
cinna: Who is good with photo editing? Dm me pls
10 hours ago 2 Replies 0 Medals
CecePitbull: guess who made no kings protest signsud83eudd2d
11 hours ago 3 Replies 0 Medals
HeyItsAlicia: Mits midnight!!! Happy 16th bday to me !!
17 hours ago 40 Replies 8 Medals
XShawtyX: Art
17 hours ago 3 Replies 1 Medal
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!