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

eid_al_fitr_wishes()

#clcoding.com

Explanation: 

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!

0 Comments:

Post a Comment

Popular Posts

Categories

100 Python Programs for Beginner (53) AI (34) Android (24) AngularJS (1) Assembly Language (2) aws (17) Azure (7) BI (10) book (4) Books (173) C (77) C# (12) C++ (82) Course (67) Coursera (226) Cybersecurity (24) data management (11) Data Science (128) Data Strucures (8) Deep Learning (20) Django (14) Downloads (3) edx (2) Engineering (14) Excel (13) Factorial (1) Finance (6) flask (3) flutter (1) FPL (17) Google (34) Hadoop (3) HTML&CSS (47) IBM (25) IoT (1) IS (25) Java (93) Leet Code (4) Machine Learning (59) Meta (22) MICHIGAN (5) microsoft (4) Nvidia (3) Pandas (4) PHP (20) Projects (29) Python (932) Python Coding Challenge (363) Python Quiz (24) Python Tips (2) Questions (2) R (70) React (6) Scripting (1) security (3) Selenium Webdriver (3) Software (17) SQL (42) UX Research (1) web application (8) Web development (2) web scraping (2)

Followers

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