print random japanese symbols in green color in columns in python

To print random Japanese symbols in green color in columns in Python, we can use the random module to generate the desired number of symbols, the termcolor module to display them in green color, and the columnar module to display the symbols in columns.

Here's the code:

main.py
import random
from termcolor import colored
import columnar

# Define the number of symbols and columns
n_symbols = 10
n_cols = 5

# Generate the list of symbols
symbols = [chr(random.randint(0x3040, 0x30FF)) for i in range(n_symbols)]

# Create a list of lists for the columnar function
data = [[colored(symbol, 'green')] for symbol in symbols]

# Display the symbols in columns
columns = columnar.concat(data, heading=None, rowstr='', colstr='  ',
                          terminal_width=100, wrap_text=False,
                          delim='\n', justify='left')
print(columns)
582 chars
20 lines

In this code, we first import the random module and the colored function from the termcolor module to display text in green color. We also import the columnar module to display the symbols in columns.

We then define the number of symbols and columns we want to display.

Next, we generate a list of n_symbols random Japanese symbols using the chr function and the random.randint function to generate random Unicode codepoints within the range of Japanese characters.

We create a list of lists for the columnar function with each symbol being colored green using the colored function.

Finally, we display the symbols in columns using the columnar function and print the result to the console.

gistlibby LogSnag