Python Forum

Full Version: counting down in while with refresh
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,
I want to make a countdown. I have 2 problems:

1)I want every second refresh, I mean after 10 i want see 9, but without 10 etc.
2)Word "Start" I want see also after 1 second delay.Now I see this word immediately(without 1 second delay).

import time

n=11
while n>1:
    n=n-1
    time.sleep(1)
    print(n)
    
print("Start")
The following works for me in a bash terminal. It won't refresh lines in a python IDE however.
import time
 
n=11
while n>1:
    n=n-1
    time.sleep(1)
    print('{:<2}'.format(n), end='\r')
time.sleep(1)
print("Start")