Wish Happy New Year 2024 in Python - PySeek (2024)

Wish Happy New Year 2024 in Python - PySeek (1)

Table of Contents

Introduction

As 2023 fades into the sunset, it’s time to start planning for the fresh possibilities of 2024! And what better way to celebrate than with a little Python magic? Forget store-bought cards and generic greetings – let’s code our own Happy New Year wishes, adding a touch of techy creativity to the occasion. In this tutorial, you will learn How you can wish Happy New Year 2024 in Python.

We will create two Python programs here. The first one will continuously print Happy New Year 2024 message with random celebrating icons on the terminal or command prompt. The second program will print fascinating colourful ASCII text messages: “Happy New Year”, “2024” same way as the first one.

So, are you ready to witness the power of Python? This coding journey will transform your New Year’s wishes into masterpieces.

The First Program

The first program is pretty simple and requires no additional installations. Just run the script, and watch your terminal erupt with a festive shower of Happy New Year 2024 wishes. It’s like throwing a digital confetti party, but with way less cleanup.

Need to cool down the party? No problem. Just tap that ctrl+C combo to break the loop of the program.

Code

import timefrom random import randintfor 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 New Year 2024🎉') 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 + "❤️") else: print(space + "🔸") space = '' time.sleep(0.2)

Output

How the program works?

The basic idea behind this program is to manipulate random numbers. Let’s break down how it works.

In the program, I’ve set up a for loop for integer numbers ranging from 1 to 85, but it doesn’t print anything. Then, there’s another for loop with numbers ranging from 1 to 1000. In each iteration, the program generates a random number between 1 and 100, storing it in the count variable. The program then prints spaces until the count variable reaches zero.

Following that, the program prints emojis, text, or both based on the modulus result (if i % number equals zero, where ‘number’ is 10, 9, 8, 7, or 6). Finally, for each iteration, the program introduces a delay of 0.2 seconds.

The Second Program

Remember how we displayed “Happy New Year 2024” in the terminal before? This time, let’s make it shine! Instead of plain text, we’ll use Python’s pyfiglet and termcolor modules to create a colourful ASCII masterpiece.

Want to learn more about these modules? Check out this tutorial: [Wish Your Friends with Stylish Text in Python].

These fancy tools aren’t built-in, so we’ll need to install them first. Ready to get started?

Requirements and Installations

Time to add some sparkle! Install pyfiglet and termcolor with these commands:

  • pyfiglet: pip install pyfiglet
  • termcolor: pip install termcolor

Download `fonts.txt` file

The program picks a surprise font (from 419 options) and color for your Happy New Year wishes. Instead of listing hundreds of fonts in the code, I saved them in a separate file you can download below. Just click the button, and the program will use that file to choose the perfect font and color for your next message!

fontsDownload

Remember, the program needs the “fonts.txt” file to be in the same folder as the program file.

Code

Want to make your New Year’s wish extra special? Just type the person’s name in the “message” variable!

import timeimport timeimport randomimport pyfiglet as pffrom pyfiglet import Figletfrom termcolor import colored# The messageText = "Happy New Year 2024"# Additional Message/Name of the Personmessage = ""# Reverse your given namereverseText = message[::-1]colorList = ['red', 'green', 'yellow', 'blue']timeInterval = [0.2, 0.3, 0.2, 0.4]# Getting all the font types from 'font.txt'# and storing into a list#==================================dataList = list()with open('fonts.txt') as f: for line in f: dataList.append(line.strip())#==================================# This part of the code prints the message# with different font types(fixed and randomly)#==================================for i in range(1,1000): if(i%10==0): textArt = pf.figlet_format(Text) print("n", textArt) elif(i%9 == 0): textArt = pf.figlet_format(Text, font="xsbook") print(textArt) elif(i%5==0): F = Figlet(font=random.choice(dataList)) textArt = colored(F.renderText(message), random.choice(colorList)) print("n", textArt) elif(i%8==0): F = Figlet(font=random.choice(dataList)) textArt = colored(F.renderText(Text), random.choice(colorList)) print("n", textArt) elif(i%7==0): textArt = pf.figlet_format(Text, font=random.choice(dataList)) print("n", textArt) elif(i%4==0): textArt = pf.figlet_format(reverseText, direction = "right-to-left") print("n", textArt) else: print("") time.sleep(random.choice(timeInterval))#==================================

Output

Summary

In this article, we explored the idea of wishing someone Happy New Year 2024 in Python. Here, we create two Python programs that’ll make your New Year wishes sparkle!

The first program uses loops and random numbers to print fun birthday messages with emojis and text. The second program uses the ‘pyfiglet’ and ‘termcolor’ modules to display a vibrant Birthday Message with the person’s name in ASCII text form on the Terminal or Command Prompt.

So, ready to make someone’s New Year sparkle? Grab the code and get coding!

If you want more Python awesomeness, Check out our Cool Python Programs page! Below are a few instances to spark your interest.

  • Say I Love You in Python Code
  • 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

Happy coding, and may your new year be coded with passion, debugged with patience, and deployed with success!

Wish Happy New Year 2024 in Python - PySeek (2024)
Top Articles
Latest Posts
Article information

Author: Frankie Dare

Last Updated:

Views: 6377

Rating: 4.2 / 5 (53 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Frankie Dare

Birthday: 2000-01-27

Address: Suite 313 45115 Caridad Freeway, Port Barabaraville, MS 66713

Phone: +3769542039359

Job: Sales Manager

Hobby: Baton twirling, Stand-up comedy, Leather crafting, Rugby, tabletop games, Jigsaw puzzles, Air sports

Introduction: My name is Frankie Dare, I am a funny, beautiful, proud, fair, pleasant, cheerful, enthusiastic person who loves writing and wants to share my knowledge and understanding with you.