print random symbols one by one and flush in python

You can use the random module to generate random symbols and the sys module with flush=True option to flush the buffer after each print statement. Here's an example code block:

main.py
import random
import sys

# set of symbols to choose from
symbols = ['*', '+', '-', '/', '%', '#']

# loop to print random symbol and flush
for i in range(10):
    sym = random.choice(symbols)
    print(sym, end='', flush=True)
228 chars
11 lines

In the above code, we first define a set of symbols to choose from. Then we use a loop to print 10 random symbols one by one using random.choice() method. Finally, we set end='' to prevent the print() statement from appending a newline character, and use flush=True option to flush the buffer after each print statement.

gistlibby LogSnag