Python Forum
counting down in while with refresh
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
counting down in while with refresh
#1
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")
Reply
#2
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")
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Refresh token for Wyze SDK duckredbeard 0 1,102 May-16-2022, 04:33 AM
Last Post: duckredbeard
  Refresh data in python script while running in Terminal frankenchrist 4 7,211 Feb-03-2021, 09:54 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020