Home > OS >  Program blinking exit dots
Program blinking exit dots

Time:11-04

I'm trying to make a message that appears when exiting the program. What I want it to look like is like this:

    1. print the word "Quitting"
    2. repeat 3 times:
      - halt for 0.5 seconds
      - print a dot in the same line with the word "Quitting"
    3. show the prompt in a new line
I wrote the code for it, But the problem is: either it shows the dots each 0.5 sec but vertically, or it waits for (0.5*3) sec to show everything (even the word "Quitting").

The code:

    print("Quitting", end='')
    for i in range(3):
        print('.', end='')
        time.sleep(0.5)
    print('\n')

CodePudding user response:

This appears to be a duplicate, but code works if you do it like this:

import time

print("Quitting", end='')
for i in range(3):
    print('.', end='', flush=True)
    time.sleep(0.5)
print('\n')

CodePudding user response:

Answer:

import time

print("Quitting", end='', flush=True)
for i in range(3):
    print('.', end='', flush=True)
    time.sleep(0.5)
print('\n')
  • Related