Answer the question
In order to leave comments, you need to log in
Can't deal with random output of colored characters in Python?
import random
import string
x=list(string.ascii_uppercase+string.digits)
for i in range(10):
random.shuffle(x)
print(*x)
Answer the question
In order to leave comments, you need to log in
if the console understands ANSI codes, then
import random
import string
GREEN = '\033[92m'
RED = '\033[91m'
ENDC = '\033[0m'
x=list(string.ascii_uppercase+string.digits)
for i in range(10):
random.shuffle(x)
y = [GREEN+l if random.random() > 0.1 else RED+l for l in x]
print(*y)
print(ENDC)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question