Saturday, 11 May 2024

Happy Mother's Day!

 


Code:

import pyfiglet

from termcolor import colored

import random

def get_random_font_style():

    # List of available Figlet font styles

    font_styles = pyfiglet.FigletFont.getFonts() 

    # Choose a random font style from the list

    return random.choice(font_styles)

def get_random_color():

    # List of available colors

    colors = ['red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white']

    # Choose a random color from the list

    return random.choice(colors)

def wish_mothers_day():

    # Get a random font style and color

    random_font_style = get_random_font_style()

    random_color = get_random_color()

    # Create a Figlet font object with the random style

    font = pyfiglet.Figlet(font=random_font_style)

    # Print the decorative greeting in the chosen color

    print(colored(font.renderText("Happy Mother's Day!"), random_color))

wish_mothers_day()

#clcoding.com

Solution and Explanation:

This code generates a Mother's Day wish with a randomly selected font style and color using the pyfiglet and termcolor libraries in Python. Here's a breakdown of what each part of the code does:

import pyfiglet: Imports the pyfiglet library, which is used to create ASCII art text.

from termcolor import colored: Imports the colored function from the termcolor library, which is used to add color to text in the terminal.

import random: Imports the random module, which is used to generate random font styles and colors.

get_random_font_style(): Defines a function that returns a random font style chosen from the available Figlet font styles provided by pyfiglet.

get_random_color(): Defines a function that returns a random color chosen from a predefined list of colors.

wish_mothers_day(): Defines the main function responsible for printing the Mother's Day wish. Inside this function:

random_font_style is assigned a random font style using get_random_font_style().
random_color is assigned a random color using get_random_color().
A Figlet font object is created using the random font style.
The text "Happy Mother's Day!" is rendered using the chosen font style and colored with the chosen color using the colored function.
The rendered text is printed to the console.
wish_mothers_day(): Finally, the wish_mothers_day() function is called to generate and print the Mother's Day wish with a random font style and color.

This code allows you to produce colorful and decorative Mother's Day wishes each time it's run, adding a touch of randomness and visual appeal to the message.


0 Comments:

Post a Comment

Popular Posts

Categories

AI (33) Android (24) AngularJS (1) Assembly Language (2) aws (17) Azure (7) BI (10) book (4) Books (146) C (77) C# (12) C++ (82) Course (67) Coursera (198) Cybersecurity (24) data management (11) Data Science (106) Data Strucures (8) Deep Learning (13) Django (14) Downloads (3) edx (2) Engineering (14) Excel (13) Factorial (1) Finance (6) flask (3) flutter (1) FPL (17) Google (21) Hadoop (3) HTML&CSS (47) IBM (25) IoT (1) IS (25) Java (93) Leet Code (4) Machine Learning (46) Meta (18) MICHIGAN (5) microsoft (4) Nvidia (1) Pandas (3) PHP (20) Projects (29) Python (893) Python Coding Challenge (285) Questions (2) R (70) React (6) Scripting (1) security (3) Selenium Webdriver (2) Software (17) SQL (42) UX Research (1) web application (8)

Followers

Person climbing a staircase. Learn Data Science from Scratch: online program with 21 courses