My Charts

chartFor this challenge we are going to use Python turtle to create some charts: Column charts, line charts and radar charts.

First we need a data set. We will use the following data that shows the market share of the four most popular browsers in 2015.

Web-browser Percentage
Chrome 44%
Safari 20%
IE / Edge 14%
Firefox 12%
Other 10%

Your Challenge


Using Python Turtle, create the following charts:
chart-column

chart-line

chart-radar

Python Turtle


Looking at the following code can you explain the purpose of each Python Turtle instructions:

  • myPen.color(“red”)
  • myPen.forward(100)
  • myPen.right(90)
  • myPen.left(45)
  • myPen.penup()
  • myPen.pendown()
  • myPen.goto(0,0)
  • myPen.beginfill()
  • myPen.end_fill()
  • myPen.begin_fill()
  • myPen.write(“Hello World”, None, “center”, “16pt bold”)

(x,y) coordinates using Python Turtle?


quadrant-coordinatesOn this trinket widget the turtle screen is 400 pixels wide by 400 pixels high. So:

  • the top left corner coordinates are (-200,200)
  • the top right corner coordinates are (200,200)
  • the bottom left corner coordinates are (-200,-200)
  • the bottom right corner coordinates are (200,-200)
  • the centre of the screen coordinates are (0,0)



Look at the canvas below to understand how (x,y) coordinates work:

Challenge #1: Complete the code


We have started the code by creating a function called drawColumnChart(). This function takes five parameters – the values of the five columns to appear on the chart.

The code below shows you how to draw the first column. Your job consists of completing this code to draw all five columns.

Challenge #2: Line chart


Using a similar approach add a new function called drawLineChart() to draw a line chart using the same five values.
chart-line

Challenge #3: Radar chart


Using a similar approach add a new function called drawRadarChart() to draw a radar chart using the same five values.
chart-radar

Share Button
Posted in Computer Science, Python - Intermediate, Python Challenges Tagged with: ,

Our Latest Book

Follow this blog