Python Turtle Program To Create Bar Graph

Python Code

import turtle


def barGraph(var1, value):
    var1.begin_fill()
    var1.left(90)
    var1.forward(value)
    var1.write(" " + str(value))

    var1.right(90)
    var1.forward(40)
    var1.right(90)
    var1.forward(value)
    var1.left(90)
    var1.end_fill()
    var1.forward(10)


a = turtle.Screen()
a.bgcolor("white")
var1 = turtle.Turtle()
var1.color("black", "light green")
var1.pensize(3)
measureheight = [160, 70, 180, 220, 60, 300]
for i in measureheight:
    barGraph(var1, i)

turtle.done()

Output

python-turtle-program-to-create-bar-graph

Leave a comment