Wish Happy Birthday🎂 in Python Code: The Original Program

a python program to for wishing happy birthday - PySeek

Introduction

Birthday is one of the happiest days in the life of every human being. Everyone hopes that his/her loved ones will greet him/her uniquely on this day. Some give a sudden surprise, some people wish by eye-catching gifts, etc.

But as a Python Programmer, an idea strike to my mind. I thought if I could create a python program to wish someone a happy birthday, it would be an unprecedented activity. In this python tutorial, I will show you how to wish someone Happy Birthday in Python Code.

This code is too simple and very surprising, and you don't need to install any extra packages or modules. Just run the program and press ctrl+C to stop.

Visit Also: Draw the Sketch of Lionel Messi using a Python Program

The Code



'''Happy Birthday in Python Code
- The Original One'''
import time
from random import randint

for i in range(1,85):
print('')

space = ''
for i in range(1,1000):
count = randint(1, 100)
while(count > 0):
space += ' '
count -= 1
if(i%10==0):
print(space + '🎂Happy Birthday!')
elif(i%9 == 0):
print(space + "🎂")
elif(i%5==0):
print(space +"💛")
elif(i%8==0):
print(space + "🎉")
elif(i%7==0):
print(space + "🍫")
elif(i%6==0):
print(space + "Happy Birthday!💖")
else:
print(space + "🔸")
space = ''
time.sleep(0.2)

Output


How the Program Works?

The working principle of this program is nothing but play with random numbers. Let's unpack the logic behind it.

Look, I declared a for loop for integer numbers, range 1 to 85. It will print nothing.

Next, another for loop is there; this time the number range is 1 to 1000. For every iteration the program will take a random number between 1 to 100 and store it to the 'count' variable. Next, spaces will print until the value of the 'count' variable reaches to zero.

After that, the program will print emoji, or text, or both on the basis of modulus result(if 'i%number' is equal to zero, where the number is 10, or 9, or 8, or 7, or 6).

At last, for each iteration the program will take a sleep time for 0.2 seconds.

Convert the python program to an executable file

Suppose you want to wish happy birthday to one of your friends through this python code, but he or she is not familiar with python programming. In this case, how would this unique idea work?

Don't worry; there is a solution for it. You can send the executable file of this program instead of sending the entire code. Let's see how to convert a python code to an executable file. But before doing so, you have to install a python module named PyInstaller in your system.

Convert python program file to exe file - PySeek

☞Install pyinstaller: pip install pyinstaller (use pip3 for Linux)

Windows

Go to the command prompt and change the current working directory(CWD) to the folder where the program file is. Then run this command.

☞pyinstaller --onefile -w birthday_code.py

Linux

Almost the same command for Linux except for a small change.

☞pyinstaller --onefile birthday_code.py

Summary

In this section, you learned how to Send Birthday Wishes as a Python Programmer. In closing, we have seen how to convert the program to an executable file for those who aren't familiar with python programming. So that you can send the executable file directly instead of the whole program.

Do share this code with your friends on their Birthday. I hope he/she will surprise for it.

There is another way to wish someone happy birthday through python programming. I have made a separate article on this topic in detail. The program works in much the same way but in this case prints ASCII text art instead of plain text. Check this out also: Wish Your Friends with Stylish TExt in Python

To get more lovely python topics, visit the separate page created only for Unique Examples. Some examples are given below.

👉Communicate with Your Friends Secretly using Python

👉Draw the Sketch of Lionel Messi using a Python Program

👉Create a Time Wasting Websites Blocker using Python

👉Check the strength of your password using python

Please share your love❤️ and leave your comment below. You'll get a reply soon.

Thanks for reading!💙

PySeek

Subhankar Rakshit

Meet Subhankar Rakshit, a Computer Science postgraduate (M.Sc.) and the creator of PySeek. Subhankar is a programmer, specializes in Python language. With a several years of experience under his belt, he has developed a deep understanding of software development. He enjoys writing blogs on various topics related to Computer Science, Python Programming, and Software Development.

6 Comments

  1. Traceback (most recent call last):
    File "C:/Users/Hario/OneDrive/Desktop/happy.py", line 10, in
    count = randing(1, 100)
    NameError: name 'randing' is not defined. Did you mean: 'randint'?
    happy
    Traceback (most recent call last):
    File "", line 1, in
    happy
    NameError: name 'happy' is not defined
    "Arrer problem"

    ReplyDelete
  2. Is the program required any third-party module?

    ReplyDelete
    Replies
    1. No, You don't need to install any extra third-party module, to run this Birthday Program.

      Delete
Post a Comment
Previous Post Next Post