0

I am working on making a count down time for a class in school and when I print it it looks like this:

0 months 14 days 10 hours 3 min 24seconds
0 months 14 days 10 hours 3 min 23seconds
0 months 14 days 10 hours 3 min 22seconds
0 months 14 days 10 hours 3 min 21seconds

is there any way to make it every time it prints a line, it deletes it so it looks like the numbers are changing something like this:

0 months 14 days 10 hours 3 min 24seconds

and then on the same line:

0 months 14 days 10 hours 3 min 23seconds

I realize there are a million answers online, but none of them seem work for my computer. I am using a Mac running OS X Yosemite with python 3.5.3. If anybody finds anything that works here please let me know.

Jacob Green
  • 61
  • 1
  • 10

2 Answers2

0

You can clear the screen between prints. (Here's an example on Windows) :

import os
from time import sleep
cls = lambda: os.system('cls')

for i in range(1000):
    print i
    sleep(1)
    cls()

For other systems, see this thread.

Community
  • 1
  • 1
Eric Duminil
  • 52,989
  • 9
  • 71
  • 124
0

This is just an example of how you can do it. You would have to modify it according to your needs.

from time import sleep

for i in range(10):
    print('\r{}'.format(i), end="")
    sleep(0.5)
Ma0
  • 15,057
  • 4
  • 35
  • 65