1

im a beginner at python and i've come across what is probably a simple problem. I want the code below to print the "." x times, each .100 of a second after each other. This is what ive got, but it just prints it all at once after x * .100 seconds. It would also help if you could redirect me to something that explains why it dosnt work or if you explained why it dosnt work.

import time
for i in range(x):
    print(".", end="")
    time.sleep(.100)

Thanks in advance.

PS. If the code is completely wrong please say so.

Rallph
  • 19
  • 1
  • 4

1 Answers1

1

Just printing doesn't mean that the content is flushed - i.e. it can still be in a buffer in your terminal or execution environment.

You can append flush=True to the arguments to print in python3 to make it flush the output as well:

import time

for i in range(x):
    print(".", end="", flush=True)
    time.sleep(.100)
MatsLindh
  • 49,529
  • 4
  • 53
  • 84