I am trying to make a function that will count down from 10 to 1 and only show one number at a time.
ex: after one second the screen reads: 10
;
Next second it reads: 9
(not 10 9
)
Here is my code (without attempted solutions):
def countdown():
import time
for i in range(10,0,-1):
time.sleep(1)
print(i,end=" ")
I have already tried using \r
,\b
, and even sys.stdout.write('\033[D \033[D')
and similar items to that using sys.stdout.write
.
None of the solutions I have previously found on StackOverflow have worked; giving me outputs such as:
10[D 9[D 8[D
etcetera.
I program in python 3.9.0 in IDLE on a mac computer.
(P.S., This countdown function is called after something else that has a print so I do not want to clear the entire screen.)
Thanks in advance to anyone who tries to help!