Send Valentine’s Day Greeting by writing Python code

Hai guys, I am going to show you a different way to propose to your loved one on Valentine’s day. I will show you how to write a python code that says I love you

Valentine’s Day is here. I’ve not decided what gift I’ll give to my girl. Selecting the right gift is a huge challenging task for me, as I’m not a creative person in this romance area. Most of the time I chose to give flowers and gift cards, because those are the things presented by every lover on valentine’s day, which also made her really upset.

But this year, I wanted to do something different and I have been learning python for the last couple of months, and I just thought of making valentine’s greetings by writing a python code.

I have written the 28 lines python code which is give a message like this 

In this article, I would like to share the python code that prints red heart by saying I love You, just a quick disclaimer, use this at your own risk, as it’s a recommendation from a “nerd”.

Here is the python code you code just copy this code. You could run this python code on any python IDE, If you don’t have python installed on your system, you could use the online python sites or you can install the python3 app on your mobile

import turtle
turtle.bgcolor("black") 
# Creating a turtle object(pen)
pen = turtle.Turtle()
pen.pencolor("red")
# Defining a method to draw curve
def curve():
 for i in range(200):
  pen.right(1)
  pen.forward(1) 
# Defining method to draw a full heart
def heart(): 
 pen.fillcolor('red')
 pen.begin_fill()
 pen.left(140)
 pen.forward(113)
 curve()
 pen.left(120)
 curve()
 pen.forward(112)
 pen.end_fill()
# Defining method to write text
def txt():
 pen.up()
 pen.setpos(-68, 95)
 pen.down()
 pen.color('black')
 pen.write("I love Python", font=( "Verdana", 5, "bold"))
heart()
txt()

pen.ht()

I have added comments for each block so that you can easily understand or you could edit it as you like. 

In this code I have mentioned “I love Python” you can change it to anything you like, To change the text see the below code and from there you can change the bold text to change the message in the output

# Defining method to write text
def txt():
pen.up()
pen.setpos(-68, 95)
pen.down()
pen.color('black')
pen.write("I love Python", font=( "Verdana", 5, "bold"))
heart()
txt()

pen.ht()

If you feel this guide is useful, Please do check out more outstanding staff here. For the updates on the latest tech news, gadgets, and tips and tricks. Follow us on our Instagram.

1 thought on “Send Valentine’s Day Greeting by writing Python code”

Leave a Comment

18 − 18 =