I understand that you're problem is that the for loop runs for more than 1 second because os.system('cls')
is not instantaneous:
You can test this by using the timeit
module in Python:
Without os.system('cls')
:
import time
import timeit
import os
start = timeit.default_timer()
for a in range(10, 0, -1): # total time is actually 1 second. no float allowed for arg 3.
print(a)
time.sleep(0.1) #unknown time...
stop = timeit.default_timer()
print('Time: ', stop - start)
Output:
10
9
8
7
6
5
4
3
2
1
Time: 1.0021432
With os.system('cls')
:
Time: 1.7151739000000001
You cannot solve this because even without os.system('cls')
it takes more than 1 second. The function os.system('cls')
itself already takes about 0.1649219
seconds to execute. You cannot make Python library function faster.