Birthday Wishes Using Python With Source Code
Introduction :
Hello Curious Coders,
In this Project we are going to generate simple Birthday wishes using turtle package in python. Turtle is a package in python which is responsible to produce some graphics. So here is the Code….
Source Code
import turtle
# Create a turtle object
my_turtle = turtle.Turtle()
# Set the turtle's speed to fast
my_turtle.speed(10)
# Set the turtle's pen color to red
my_turtle.pencolor("red")
# Move the turtle to the starting position
my_turtle.penup()
my_turtle.goto(-150, 0)
my_turtle.pendown()
# Write the word "Happy"
my_turtle.write("Happy", font=("Arial", 36, "bold"))
# Move the turtle to the next position
my_turtle.penup()
my_turtle.forward(200)
# Write the word "Birthday"
my_turtle.write("Birthday", font=("Arial", 36, "bold"))
# Hide the turtle when done
my_turtle.hideturtle()
# Keep the turtle window open
turtle.done()
Code Explanation
- First, we imported the turtle module using the line
import turtle
. - Then, we created a turtle object using the line
my_turtle = turtle.Turtle()
. This creates an instance of the turtle class, which we can use to control the turtle’s movements and drawing. - Next, we set the turtle’s speed to fast using the line
my_turtle.speed(10)
. This sets the turtle’s animation speed, with 10 being the fastest setting. - After that, it sets the turtle’s pen color to red using the line
my_turtle.pencolor("red")
. This sets the color of the turtle’s pen, which is used to draw on the screen. - Next, it moves the turtle to the starting position using the lines
my_turtle.penup()
,my_turtle.goto(-150, 0)
, andmy_turtle.pendown()
. The turtle’s starting position is set to (-150, 0) on the x-y plane. Thepenup()
method is used to lift the turtle’s pen off the screen so it can move to the new position without drawing. Thependown()
method is used to put the pen back on the screen so it can begin drawing again. - Then, it writes the word “Happy” using the line
my_turtle.write("Happy", font=("Arial", 36, "bold"))
. This uses the turtle’swrite()
method to write the word “Happy” in red, bold font using Arial font of size 36. - After that, it moves the turtle to the next position using the line
my_turtle.penup()
,my_turtle.forward(200)
. This moves the turtle 200 units forward from its current position. - Finally, it writes the word “Birthday” using the line
my_turtle.write("Birthday", font=("Arial", 36, "bold"))
. This uses the turtle’swrite()
method to write the word “Birthday” in red, bold font using Arial font of size 36. - Then, it hides the turtle using the line
my_turtle.hideturtle()
. This makes the turtle invisible on the screen. - Finally, it keeps the turtle window open using the line
turtle.done()
. This keeps the turtle window open until the user closes it. - Overall, this code uses the turtle module to create a turtle object, set its properties, and use its methods to write the words “Happy” and “Birthday” on the screen.
Output:
Find More Projects
Build a Quiz Game Using HTML CSS and JavaScript Introduction Hello coders, you might have played various games, but were you aware …
Emoji Catcher Game Using HTML CSS and JavaScript Introduction Hello Coders, Welcome to another new blog. In this article we’ve made a …
Typing Challenge Using HTML CSS and JavaScript Introduction Hello friends, all you developer friends are welcome to our new project. If you …
Breakout Game Using HTML CSS and JavaScript With Source Code Introduction Hello friends, welcome to today’s new blog post. All of you …
Digital and Analog Clock using HTML CSS and JavaScript Introduction : This project is a digital clock and stopwatch system, which allows …
Coffee Shop Website using HTML, CSS & JavaScript Introduction : This project is a website for coffee house business. It uses HTML …