I want to print only two lines in my cycles, I started with the following:
import time
for i in range(10):
time.sleep(0.5)
for j in range(10):
time.sleep(0.5)
print('Index1:', i)
print('Index2:', j)
I tried different combinations of \r, \n, flush=True etc. at the beginning and end of print, but wasn’t successful((
What I’d like to see is as in the GIF of accepted answer here
I tried those code, but it didn’t help, maybe because my OS is Windows or I use jupyter notebook, I have no idea((
>Solution :
import time
n = 15
for i in range(n):
print(f"{i}s passed")
print(f"{n-i}s remaining")
time.sleep(1)
print("\u001b[2A", end="") #ANSI escape code for cursor up
Does this code snippet help you?