0

Let's assume there is a code which is using with anaconda prompt. While the program flowing, every second is printing to screen. However, here every second is printed the same or next line. I want to print every second in the same place. For example, print 30 and after 1 second later, delete 30 and print 29 to the same place.

How can I do that with python?

dralioz
  • 49
  • 5

2 Answers2

0

You can use \r to return to the start of line instead of moving the cursor to the next line (\n). Whether or not this works with your shell is an open question; e.g. IDLE occasionally has problems with this.

import time
for x in range(10):
    print(x, end='\r')
    time.sleep(1)
print()  # to add a newline, finally
print('The end!')
AKX
  • 152,115
  • 15
  • 115
  • 172
0

After every second when you have to clear the screen you can use this :

import os
os.system('cls')
paradocslover
  • 2,932
  • 3
  • 18
  • 44