You can download this code by clicking the button below.
This code is now available for download.
This function randomly selects a color from a predefined list and prints it using the Rich library's Console object, with the text styled in bold and the selected color.
Technology Stack : Rich, random
Code Type : Function
Code Difficulty : Beginner
def generate_random_color():
import random
from rich.console import Console
console = Console()
colors = ["red", "green", "blue", "yellow", "purple", "orange"]
random_color = random.choice(colors)
console.print(f"Random color is: {random_color}", style=f"bold {random_color}")