You can download this code by clicking the button below.
This code is now available for download.
This function accepts a color code as an argument and returns a string marked with the color code. If an invalid color code is provided, it returns an error message.
Technology Stack : colorama, random
Code Type : Function
Code Difficulty : Intermediate
def random_color(arg1):
from colorama import Fore, Back, Style
import random
colors = [Fore.RED, Fore.GREEN, Fore.YELLOW, Fore.BLUE, Fore.MAGENTA, Fore.CYAN, Fore.WHITE]
if arg1 not in colors:
return "Invalid color code"
return f"{arg1}Your text here{Style.RESET_ALL}"