Question: PYTHON Assume you have a list of data points that represents the grades earned on a particular project in the class. The max grade is
PYTHON
Assume you have a list of data points that represents the grades earned on a particular project in the class. The max grade is out of 280 points. Currently, the code fills all values with the same color. We want to visually see where the grades lay in terms of their letter grade equivalent. Since a grade of C is average, we color those values that lay within this range differently. Project values ranging from [196, 224) are in the C range. Color these values green. All other grade values will be colored red.
Much of the code has been done for you. Modify the code within the for-loop so that the color changes depending on each grade value.
Modify the existing code so that:
1. If the grade value is 196 or more but less than 224 then change the fill color to green, otherwise change the fill color to red.
2. Test your code. Your code is correct once it appears as shown below.
Challenge: Make all A grades Blue, B grades Orange, C grades Green, D grades Yellow and all the rest red.
Existing code:
my_grades = [48, 224, 117, 200, 196, 240, 160, 223, 260, 220] # here is the grades data maxheight = max(my_grades) numbars = len(my_grades) border = 10 # border width so that the graph is centered in the middle of the canvas wn.setworldcoordinates(0-border, 0-border, 40*numbars+border, maxheight+border) # set the coordinate so that the canvas represents the first quadrant and all data is proportional to the size of the canvas. wn.bgcolor("lightblue")
linda = turtle.Turtle() # create linda and set some attributes linda.color("blue") linda.pensize(3) linda.speed(0)
for a in my_grades: linda.fillcolor('red') linda.begin_fill() # start filling this shape drawBar(linda, a) linda.end_fill() # stop filling this shape
wn.exitonclick()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
