D
D
Dmitry2017-01-21 22:54:53
Python
Dmitry, 2017-01-21 22:54:53

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)

ideally, I would like to display characters ala like in a matrix movie (green characters and random in a different color, for example, red), but since I'm just learning and banned in Google, I can't figure out how to make a color, not how to implement random numbers in a random list

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2017-01-22
@ipatov_dn

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)

A
Alexander, 2017-01-22
@Alex1OPS

Pay attention to colorama

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question