matt-333 matt-333 - 1 month ago 7
Python Question

How to print a string one word at a time, on one line with all of the string visible. - Python

I want to make the word: 'error' repeat itself numerous times. This is an easy task in itself, but I do not know how to print them one at a time, at whatever speed I choose. I understand that my question has been partially covered, but I do not wish for the previous word of the string to dissapear.

print('Error! ' *20)


The output that I want is Error! Error! (each released individually instead of being released all at once.)

How can I make it so that python does not release all of the string at the same time? It would also be good to know whether I can make it print in columns, but still along the widths.

Answer Source

This will print Error! 20 times (on 20 lines/rows), over a duration of 20 seconds

import time

for _ in range(20):
    print("Error!")
    time.sleep(1)  # change 1 to whatever number you want, to control the amount of time before "Error!" is printed again

This will print "Error!" 20 times on the same line (20 columns) over a duration of 20 seconds:

import time

for _ in range(20):
    print("Error!", end='', flush=True)
    time.sleep(1)  # change 1 to whatever number you want, to control the amount of time before "Error!" is printed again