Python program for birthday wishes

This article will discuss how to wish someone’s birthday in Python code. You’ll learn some of the fundamental ideas of Python programming in this tutorial and an overview of how to code using Python Code. You’ll write a basic program showing your birthday on the screen.

Python program for birthday wishes

Although we all frequently wish our loved ones happy birthdays, there are some people who opt not to do so. They can’t express it properly, which is why. You may learn how to say happy birthday in Python language.

Complete the program Happy Birthday Python Program In pyfiglet.

Example:

import pyfiglet
  
result = pyfiglet.figlet_format("Happy Birthday to You ", font = "slant"  )

print(result)

Bypassing the keyword “slant” as the font argument inside the figlet format() function, we will output the input supplied encoded text in the slant font in this case.

To perform this task first we will import the pyfiglet package. A Python program can utilize the Pyfiglet module’s numerous functions to generate fancy texts with high font sizes and other formatting in the output.

To install your system pyfiglet, you can easily use the following command

pip install pyfiglet

To display the Happy birthday wish we are going to use the pyfiglet.figlet_format() function. We may utilize the figlet format() function inside a Python example program because of the pyfiglet module. Using ASCII art fonts, pyfiglet renders ASCII text.

READ:  Python Remove a Newline from the String

Syntax:

Here is the Syntax of the figlet_format() function in Python

pfg.figlet_format('inputText', font = 'typeOfFont')  
  • It consists of a few parameters:
    • inputText: The function will transform the input text into complex pattern texts in the output if we pass it an argument with the input text, which is provided in ASCII-encoded form.
    • font: By default, it takes the ‘typeoffont’ value and in this function, the font type is an optional argument. This option specifies the fancy text font that will be used in the output, and the input text that has been encoded will also be printed using the same fancy text pattern. In this example, we will use the font= “slant”.

Here is the Screenshot of the following code

happy birthday programming code in python

Read Python Program for even or odd

Python code for birthday wishes

Here is another example of Python code for birthday wishes.

In this example, we will use the if and elif conditions and We can check for several expressions with this. If the if condition is False, the next elif block’s condition is checked, and so on. The body of else is executed if all the conditions are false.

import time
from random import randint

for m in range(1,10):
    print('')
 
for m in range(1,10):
    num = randint(1, 10)
    while(num > 0):
        
        num -= 1
    if(m%10==0):
        print('Happy Birthday!')
    elif(m%9 == 0):
        print( "Happy Birthday!")
    elif(m%5==0):
        print("Happy Birthday!")
    elif(m%8==0):
        print("Happy Birthday!")
    elif(m%7==0):
        print("Happy Birthday!")
    elif(m%6==0):
        print("Happy Birthday!")
    else:
        print("Happy Birthday!")
    
    time.sleep(0.2)

In the following given code, we have set the range (1,70) and iterate the values and then it comes another for loop, but this time the range of numbers is 1 to 100. The software will select a random number between 1 and 10 for each iteration and add it to the “num” variable. Then, until the value of the ‘num’ variable becomes zero, spaces will print.

READ:  How to Skip a Line in Python? [4 Ways]

Then, depending on the modulus result (if “i%number” is equal to zero, where the number is 10, 9, 8, 7, or 6), the program will output text or both. Finally, the program will take a 0.2-second nap between each iteration.

Here is the execution of the following code

python code for birthday wishes

Read Python Program to Check Leap Year

Write Happy Birthday Python Program In Turtle

In this example first, we will import the Python turtle module with ‘tur’ and then assign the title name “PythonGuides”. Next, we will use the background color as green. In the above example, we are defining the forward() and right() functions to draw a square shape.

In this piece of code, we are drawing the square of the Happy Birthday keeping the pensize of 15. The pen color and color are the same i.e. green. The position of the square is initialized to goto(80,90).

from turtle import *
import turtle as tur

turt=tur.Turtle()
tur.title("PythonGuides")
turt.width(8)
turt.color("cyan")
new=tur.getscreen()
turt.speed(10)

new.bgcolor("green")

turt.left(180)
turt.penup()
turt.forward(300)
turt.right(90)
turt.forward(100)
turt.pendown()

# Display H

turt.forward(50)
turt.right(90)
turt.forward(50)
turt.left(90)
turt.forward(50)
turt.left(90)
turt.penup()
turt.forward(50)
turt.left(90)
turt.pendown()
turt.forward(50)
turt.left(90)
turt.forward(50)
turt.right(90)
turt.forward(50)

# Display A

turt.penup()
turt.left(90)
turt.forward(15)
turt.pendown()
turt.left(70)
turt.forward(110)
turt.right(70)
turt.right(70)
turt.forward(110)
turt.left(180)
turt.forward(55)
turt.left(70)
turt.forward(38)
turt.left(70)
turt.penup()
turt.forward(55)
turt.left(110)
turt.forward(100)

# Display P

turt.left(90)
turt.pendown()
turt.forward(100)
turt.right(90)
turt.forward(50)
turt.right(20)
turt.forward(20)
turt.right(70)
turt.forward(40)
turt.right(70)
turt.forward(20)
turt.right(20)
turt.forward(50)
turt.left(90)
turt.forward(50)
turt.left(90)
turt.penup()
turt.forward(100)

# Display P

turt.left(90)
turt.pendown()
turt.forward(100)
turt.right(90)
turt.forward(50)
turt.right(20)
turt.forward(20)
turt.right(70)
turt.forward(40)
turt.right(70)
turt.forward(20)
turt.right(20)
turt.forward(50)
turt.left(90)
turt.forward(50)
turt.left(90)
turt.penup()
turt.forward(100)

# Display Y

turt.forward(20)
turt.pendown()
turt.left(90)
turt.forward(50)
turt.left(30)
turt.forward(60)
turt.backward(60)
turt.right(60)
turt.forward(60)
turt.backward(60)
turt.left(30)

# go to Home

turt.penup()
turt.home()
turt.color("yellow")
new.bgcolor("blue")
# setting second row

turt.backward(300)
turt.right(90)
turt.forward(60)
turt.left(180)

# Display P

turt.pendown()
turt.forward(100)
turt.right(90)
turt.forward(50)
turt.right(20)
turt.forward(20)
turt.right(70)
turt.forward(40)
turt.right(70)
turt.forward(20)
turt.right(20)
turt.forward(50)
turt.backward(50)
turt.left(180)
turt.right(20)
turt.forward(20)
turt.right(70)
turt.forward(40)
turt.right(70)
turt.forward(20)
turt.right(20)
turt.forward(50)
turt.right(90)
turt.forward(10)

# go to Home

turt.penup()
turt.home()

# setting up

turt.backward(200)
turt.right(90)
turt.forward(10)
turt.left(90)
turt.pendown()
turt.forward(20)
turt.penup()
turt.home()

# D

turt.backward(150)
turt.right(90)
turt.forward(60)
turt.pendown()
turt.backward(100)
turt.right(90)
turt.forward(10)
turt.backward(70)
turt.left(180)
turt.right(20)
turt.forward(20)
turt.right(70)
turt.forward(88)
turt.right(70)
turt.forward(20)
turt.right(20)
turt.forward(70)
turt.penup()
turt.home()

# set up for A

turt.backward(50)
turt.right(90)
turt.forward(65)
turt.left(90)

# printing A

turt.pendown()
turt.left(70)
turt.forward(110)
turt.right(70)
turt.right(70)
turt.forward(110)
turt.left(180)
turt.forward(55)
turt.left(70)
turt.forward(38)
turt.left(70)
turt.penup()
turt.forward(55)
turt.left(110)
turt.forward(100)

# printing Y

turt.pendown()
turt.left(90)
turt.forward(50)
turt.left(30)
turt.forward(60)
turt.backward(60)
turt.right(60)
turt.forward(60)
turt.backward(60)
turt.left(30)

# go to Home

turt.penup()
turt.home()

# settig position

turt.right(90)
turt.forward(215)
turt.right(90)
turt.forward(200)
turt.right(90)

#color

turt.color("blue")
new.bgcolor("black")

# setup
turt.penup()
turt.left(90)
turt.forward(80)
turt.left(90)
turt.forward(7)

turt.forward(100)

# design

#design pattern
turt.home()
turt.forward(200)
turt.pendown()
turt.color("PURPLE")
turt.width(3)
turt.speed(0)

def squre(length, angle):

    turt.forward(length)
    turt.right(angle)
    turt.forward(length)
    turt.right(angle)

    turt.forward(length)
    turt.right(angle)
    turt.forward(length)
    turt.right(angle)

squre(80, 90)

for i in range(36):
      turt.right(10)
      squre(80, 90)

tur.mainloop()
happy birthday code in python using turtle

Read Python program to find the area of square

Birthday wishes using the Python input function

Here is another birthday wishes using the Python input function.

In this example, we will define a function named birthday_wish and then use the input() function to get the message that today is your birthday or not. If you will type yes it will display “Happy Birthday”.

READ:  How to Square a List in Python

Source Code:

new_str = """
         __        _ _ _ _ _    _ _ _ _ _               
 |     ||  \      |         |  |         |  \      /
 |     ||   \     |         |  |         |   \    /  
 |_____||_ __\    |__ _ _ _ |  |_ _ _ _ _|    \  /     
 |     ||     \   |            |                |
 |     ||      \  |            |                |
 |     ||       \ |            |                |

  _ _ _ _  _ _ _ _    _______    _ _ _ _                 _ _ _ _ _     __
 ||     |     |       |     /       |       |       |   |         /   |  \        \    /
 ||      |    |       |    /        |       |       |   |        /    |   \        \  / 
 ||_ _ _|     |       |   /         |       |_______|   |       /     |_ _ \        \/
 ||     |     |       |  /          |       |       |   |      /      |     \        |
 ||      |    |       |   \         |       |       |   |     /       |      \       |
 ||____ |  ___|___    |    \        |       |       |   |_ _ /        |       \      |

"""
def birthday_wish():
    result = input("Is Today Your Birthday ? (Yes,No) ")
    if result == 'Yes':
        print(new_str)

birthday_wish()

Here is the implementation of the following code

happy birthday python code

In this Python tutorial, we have discussed how to wish someone’s birthday in Python code. In this section, you learned how to Send Birthday Wishes as a Python Programmer by using different methods.

You may like the following python tutorials: