DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk3 min

Happy Birthday Code in Python: 9 Programs with Output

Try nine copyable Python birthday programs, with matching output for each—from a one-line greeting to an optional turtle card.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Here are nine runnable Python birthday programs, from a one-line greeting to an optional turtle-drawn card. The first eight print in a terminal; the last opens a graphics window. Each example includes its matching output and the Python idea it demonstrates.

1. Print a simple birthday greeting

print("Happy Birthday!")

Output:

Happy Birthday!

print() displays fixed text in the terminal; this is the simplest version because the message is written directly in the program.

2. Add a name to the greeting

name = "Maya"
print("Happy Birthday, " + name + "!")

Output:

Happy Birthday, Maya!

The name variable stores text that you can change to personalize the greeting.

3. Ask for a name and age

name = input("What is the birthday person's name? ")
age = input("How old are they turning? ")
print("Happy Birthday, " + name + "! You are " + age + " today.")

Sample input: enter Maya at the first prompt and 12 at the second.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Output:

What is the birthday person's name? Maya
How old are they turning? 12
Happy Birthday, Maya! You are 12 today.

input() reads what the user types as text, so the age is kept as a string here rather than converted to a number.

4. Use a function for a reusable greeting

def birthday_greeting(name):
    print("Happy Birthday, " + name + "!")
    print("I hope your day is wonderful.")

birthday_greeting("Maya")

Output:

Happy Birthday, Maya!
I hope your day is wonderful.

A function groups instructions under a name so you can call the same greeting again with another person’s name.

5. Repeat a birthday message with a loop

for _ in range(3):
    print("Happy Birthday!")

Output:

Happy Birthday!
Happy Birthday!
Happy Birthday!

The for loop runs its indented instruction three times, avoiding three separate print() statements.

6. Format a personalized greeting

name = "Maya"
age = 12
print(f"Happy {age}th Birthday, {name}!")

Output:

Happy 12th Birthday, Maya!

An f-string inserts variable values inside a string. This example assumes an age where adding th gives the desired ordinal wording; English ordinals vary, so for other ages you may prefer to write the message without an ordinal suffix.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

7. Print a multiline birthday message

message = """Happy Birthday, Maya!
Wishing you laughter and a great year ahead.
Enjoy your special day!"""
print(message)

Output:

Happy Birthday, Maya!
Wishing you laughter and a great year ahead.
Enjoy your special day!

Triple quotes let one string contain line breaks, so print() displays the message across multiple lines.

8. Make a text-art birthday card

print("+--------------------------+")
print("|     HAPPY BIRTHDAY!      |")
print("|       Maya, enjoy!       |")
print("+--------------------------+")

Output:

+--------------------------+
|     HAPPY BIRTHDAY!      |
|       Maya, enjoy!       |
+--------------------------+

This uses ordinary text characters to draw a simple card in the terminal; edit the text while keeping the borders aligned if you change the name.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

9. Draw a birthday card with Python turtle

This optional version opens a graphics window instead of printing a card in the terminal. Python’s turtle documentation describes turtle as a way for learners to get immediate, visible feedback while encountering programming concepts. The module is in Python’s standard library, but it relies on Tk interface support, which may be packaged separately on some Linux distributions and other platforms.

import turtle as t

screen = t.Screen()
screen.title("Birthday Card")
pen = t.Turtle()
pen.hideturtle()
pen.speed(3)

pen.penup()
pen.goto(-150, 30)
pen.pendown()
pen.color("purple")
pen.write("Happy Birthday!", font=("Arial", 20, "bold"))

pen.penup()
pen.goto(-90, -20)
pen.color("blue")
pen.write("Have a wonderful day!", font=("Arial", 14, "normal"))

screen.mainloop()

Visible result: a graphics window with “Happy Birthday!” and “Have a wonderful day!” written in it. Turtle coordinates position the text, while write() draws it; change the strings to personalize the card. The final screen.mainloop() keeps the window open until you close it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

If turtle does not open

  • If the error says No module named '_tkinter', your Python installation may lack Tk support. Check the Tk package or Python build provided for your operating system.
  • Do not assume that pip install turtle is the fix: turtle is part of the standard library, while the missing piece may be the platform’s Tk interface.
  • For a greeting that only needs text, use any of Programs 1–8 instead; they do not require a graphics window.

Python.org lists Python 3.14.8, released September 30, 2026. These examples use basic Python syntax; the turtle setup note matters only when running the graphics example.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.