Question: Introduction In this project we will draw a Bar Graph using a simple graphics library called Turtle GraphicsLinks to an external site.. The requirements are
Introduction
In this project we will draw a Bar Graph using a simple graphics library called Turtle GraphicsLinks to an external site.. The requirements are as follows:
Read data points from the given text file data.txt
Each data value is separated by a new line
Convert each data value into an int
print the list of data to the console window
sort the list of data
print the sorted list to the console window
Draw a bar graph of the sorted data
Algorithm
Use readlinesLinks to an external site. to read the data from the given file into a list
To sort the list, you can research a sorting algorithm of your choice or use the library sortLinks to an external site. function
Determine the maximum data value from your list as maxheight
Count the number of data values read as numBars
Scale your graphics window coordinates to fit a height of maxheight and a width of numBars pixels
Use setworldcoordinatesLinks to an external site.
Add a little bit extra to the top right corner to create a border around your graph
To draw a bar graph of the given data:
Set your draw speed to fastest
Draw each data value as a rectangle with its height in pixels and a width pixels
Fill in each rectangle with color
Label the height of each rectangle, either above or below
Use the following functions:
beginfill
endfill
left
forward
right
write
Starter Code and Data File
Use the following as a template for your code:
SortedBarGraphTemplate.pyDownload SortedBarGraphTemplate.py
Test your code with the following file:
data.txtDownload data.txt
Turtle Graphics Tutorials
Official Python documentationLinks to an external site.
Tutorial on GithubLinks to an external site.
Output
Your program should produce something similar to the following graphs. It is fine if they display one after the other:
Unsorted Bar Graph
Sorted Bar Graph
Scoring
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
