make random green japanese alphabet and print it in python

main.py
import random

# Hiragana Japanese Alphabet
hiragana = ['あ', 'い', 'う', 'え', 'お', 
            'か', 'き', 'く', 'け', 'こ',
            'さ', 'し', 'す', 'せ', 'そ',
            'た', 'ち', 'つ', 'て', 'と',
            'な', 'に', 'ぬ', 'ね', 'の',
            'は', 'ひ', 'ふ', 'へ', 'ほ',
            'ま', 'み', 'む', 'め', 'も',
            'や', 'ゆ', 'よ',
            'ら', 'り', 'る', 'れ', 'ろ',
            'わ', 'を', 'ん']

# Randomly choose one element from hiragana list
rand_hiragana = random.choice(hiragana)

# Print the randomly chosen hiragana character in green color
print("\033[32m" + rand_hiragana + "\033[0m")
594 chars
20 lines

To explain the code above:

  1. We first import the random module, which we will use to choose a random element from the hiragana list.

  2. We define the hiragana list, which contains all the Hiragana characters of the Japanese alphabet.

  3. We use random.choice(hiragana) to choose a random element from the hiragana list and assign it to the rand_hiragana variable.

  4. We print out the randomly chosen Hiragana character in green color by using ANSI escape codes. We start the string with "\033[32m" to turn the color green (\033[32m), then add the random character, and end the string with "\033[0m" to reset the color back to the default.

gistlibby LogSnag