See how you stack up against top hiring criteria for the role in 2025.
Compare against 1000+ live job postings
Identify critical technical skill gaps
Get a personalized improvement roadmap
No signup required, takes less than 30 sec
Introduction
Python comes with tons of libraries and inbuilt functions. There are libraries for data science, machine learning, maths etc. Often, these inbuilt functions come in handy when doing a specific task in Python. We will learn how to draw hut and house using one such library of python, turtle.
Turtle
"Turtle" is a Python drawing board feature that allows us to instruct a turtle to draw all over it! . Turtle library is included in the standard Python distribution and does not require additional installation.
How to draw a Hut?
Steps
1. First, Import the turtle library in Python and set desired background colour. 2. Define three functions for drawing the Hut's front, top, and side portions. Here, the Hut's front, top, and side portions will be rectangle, equilateral triangle, and parallelogram. 3. For drawing windows and doors, use penup() and pendown() functions. 4. Last step is to fill the desired colour in the Hut.
Python Program
import turtle
import math
# Set the background color
screen = turtle.Screen()
screen.bgcolor("lightpink")
# Create our turtleObject
turtleObject = turtle.Turtle()
turtleObject.color("black")
turtleObject.shape("turtle")
turtleObject.speed(5)
# Creating a function that will draw and
# fill a rectangle with the dimensions and colour specified.
def drawRectangle(turtleObject, width, height, color):
turtleObject.fillcolor(color)
turtleObject.begin_fill()
turtleObject.forward(width)
turtleObject.left(90)
turtleObject.forward(height)
turtleObject.left(90)
turtleObject.forward(width)
turtleObject.left(90)
turtleObject.forward(height)
turtleObject.left(90)
turtleObject.end_fill()
# Creating a function that allows you to draw and fill an
# equalateral right triangle with the given hypotenuse length
# and colour. This is used to make the shape of a roof.
def drawTriangle(turtleObject, length, color):
turtleObject.fillcolor(color)
turtleObject.begin_fill()
turtleObject.forward(length)
turtleObject.left(135)
turtleObject.forward(length / math.sqrt(2))
turtleObject.left(90)
turtleObject.forward(length / math.sqrt(2))
turtleObject.left(135)
turtleObject.end_fill()
# Creating a function to create and fill a parallelogram, which will
# be used to draw the house's side.
def drawParallelogram(turtleObject, width, height, color):
turtleObject.fillcolor(color)
turtleObject.begin_fill()
turtleObject.left(30)
turtleObject.forward(width)
turtleObject.left(60)
turtleObject.forward(height)
turtleObject.left(120)
turtleObject.forward(width)
turtleObject.left(60)
turtleObject.forward(height)
turtleObject.left(90)
turtleObject.end_fill()
# drawing and filling the front of the house.
turtleObject.penup()
turtleObject.goto(-150, -120)
turtleObject.pendown()
drawRectangle(turtleObject, 100, 110, "blue")
# drawing and filling the front door
turtleObject.penup()
turtleObject.goto(-120, -120)
turtleObject.pendown()
drawRectangle(turtleObject, 40, 60, "lightgreen")
# Front roof
turtleObject.penup()
turtleObject.goto(-150, -10)
turtleObject.pendown()
drawTriangle(turtleObject, 100, "magenta")
# Side of the house
turtleObject.penup()
turtleObject.goto(-50, -120)
turtleObject.pendown()
drawParallelogram(turtleObject, 60, 110, "yellow")
# Window
turtleObject.penup()
turtleObject.goto(-30, -60)
turtleObject.pendown()
drawParallelogram(turtleObject, 20, 30, "brown")
# Side roof
turtleObject.penup()
turtleObject.goto(-50, -10)
turtleObject.pendown()
turtleObject.fillcolor("orange")
turtleObject.begin_fill()
turtleObject.left(30)
turtleObject.forward(60)
turtleObject.left(105)
turtleObject.forward(100 / math.sqrt(2))
turtleObject.left(75)
turtleObject.forward(60)
turtleObject.left(105)
turtleObject.forward(100 / math.sqrt(2))
turtleObject.left(45)
turtleObject.end_fill()
turtle.done()
You can also try this code with Online Python Compiler
You can practice by yourself with the help of online python compiler for better understanding.
How to draw a House?
Steps
1. First, Import the turtle library in Python and set desired background colour. 2. Now draw a rectangle for the base of our house. 3. Now create a triangle for the upper portion of the house. 4. Next create doors and windows.
Python Program
import turtle
t = turtle.Turtle()
# for background
screen = turtle.Screen()
screen.bgcolor("yellow")
# setting the color and speed of the turtle.
t.color("black")
t.shape("turtle")
t.speed(1)
# creating base of
# the house
t.fillcolor('cyan')
t.begin_fill()
t.right(90)
t.forward(250)
t.left(90)
t.forward(400)
t.left(90)
t.forward(250)
t.left(90)
t.forward(400)
t.right(90)
t.end_fill()
# for top of
# the house
t.fillcolor('brown')
t.begin_fill()
t.right(45)
t.forward(200)
t.right(90)
t.forward(200)
t.left(180)
t.forward(200)
t.right(135)
t.forward(259)
t.right(90)
t.forward(142)
t.end_fill()
# for door and
# windows
t.right(90)
t.forward(400)
t.left(90)
t.forward(50)
t.left(90)
t.forward(150)
t.right(90)
t.forward(200)
t.right(180)
t.forward(200)
t.right(90)
t.forward(200)
t.right(90)
t.forward(150)
t.right(90)
t.forward(200)
t.right(90)
t.forward(150)
t.right(90)
t.forward(100)
t.right(90)
t.forward(150)
t.right(90)
t.forward(100)
t.right(90)
t.forward(75)
t.right(90)
t.forward(200)
t.right(180)
t.forward(200)
t.right(90)
t.forward(75)
t.left(90)
t.forward(15)
t.left(90)
t.forward(200)
t.right(90)
t.forward(15)
t.right(90)
t.forward(75)
You can also try this code with Online Python Compiler
The reversed() function allows us to reverse the order of items in a sequence. It takes a sequence as input and returns an iterator.
2. What is an interpreted language?
The statements in an interpretable language are executed line by line. Interpreted languages include Python, Javascript, R, PHP, and Ruby. An interpreted language program executes directly from the source code, without the need for a compilation phase.
3. What are the applications of python?
Python is used for many purposes. Common applications include:
Web development
Game development
Data Science
Machine Learning
4. What are Python literals?
Literals are data that is contained within a variable or constant. Python supports different literals including strings, numerical and boolean literals
5. How are parameters passed in Python functions by default?
By default, parameters are passed by reference in Python functions.
Conclusion
Cheers if you reached here!!
In this article, we learnt about how to draw hut and house using turtle library in python.
We hope that this blog has helped you enhance your knowledge regarding turtle library in python and if you would like to learn more, check out our articles on the platform Coding Ninjas Studio. Also, do check out our course on C++. Do upvote our blog to help other ninjas grow. Happy Coding!