Tuesday 9 April 2024

Happy Eid Al-Fitr using Python


Code :

import pyfiglet

from termcolor import colored

import random

def eid_al_fitr_wishes():

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

    ascii_art = pyfiglet.figlet_format("Eid Mubarak!", font="slant")

    print(colored(ascii_art, color=random.choice(colors)))    

# Call the function to display Eid-al-Fitr wishes




Let me break down the code step by step:

import pyfiglet: This line imports the pyfiglet module, which is used for creating ASCII art text. In this script, the figlet_format() function from pyfiglet module is used to generate ASCII art for the text "Eid Mubarak!" with the specified font style ("slant").

from termcolor import colored: This line imports the colored() function from the termcolor module. The colored() function is used to add color to text printed in the terminal. It takes the text and color as arguments and returns the colored text.

import random: This line imports the random module, which provides functions for generating random numbers. It is used in this script to randomly select a color from the list of colors defined later.

def eid_al_fitr_wishes():: This line defines a function named eid_al_fitr_wishes(). This function encapsulates the logic for printing Eid-al-Fitr wishes with ASCII art and colored text.

colors = ['red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white']: This line defines a list named colors containing various color names.

ascii_art = pyfiglet.figlet_format("Eid Mubarak!", font="slant"): This line uses the figlet_format() function from the pyfiglet module to generate ASCII art for the text "Eid Mubarak!" with the specified font style ("slant"). The resulting ASCII art is stored in the variable ascii_art.

print(colored(ascii_art, color=random.choice(colors))): This line prints the ASCII art generated earlier with a randomly chosen color from the colors list. The colored() function applies the selected color to the ASCII art before printing it.

eid_al_fitr_wishes(): This line calls the eid_al_fitr_wishes() function, executing the code within it and printing the Eid-al-Fitr wishes with colored ASCII art.

That's a breakdown of the code provided. If you have any further questions or need clarification on any part, feel free to ask!


Post a Comment

Popular Posts


AI (27) Android (24) AngularJS (1) Assembly Language (2) aws (17) Azure (7) BI (10) book (4) Books (118) C (77) C# (12) C++ (82) Course (62) Coursera (180) Cybersecurity (22) data management (11) Data Science (95) Data Strucures (6) Deep Learning (9) Django (6) Downloads (3) edx (2) Engineering (14) Excel (13) Factorial (1) Finance (6) flutter (1) FPL (17) Google (19) Hadoop (3) HTML&CSS (46) IBM (25) IoT (1) IS (25) Java (92) Leet Code (4) Machine Learning (44) Meta (18) MICHIGAN (5) microsoft (4) Pandas (3) PHP (20) Projects (29) Python (753) Python Coding Challenge (230) Questions (2) R (70) React (6) Scripting (1) security (3) Selenium Webdriver (2) Software (17) SQL (40) UX Research (1) web application (8)


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