Practice and reinforce the concepts from Lesson 11
Time: 30-40 minutes
What you'll create:
In this activity, you'll learn to create interactive data visualizations using the Pygal library. You'll work with teacher data to create bar charts and practice variable incrementing operations.
Login to EduBlocks: Go to: https://app.edublocks.org/login
Import the Activity Project:
:bulb: Save Your Progress!
Remember to click the save button every few minutes! It's like saving your game progress - you don't want to lose your hard work! :emoji:
Your EduBlocks project shows teachers in Telebort and how many students they've taught in a week. Let's create a cool bar chart to visualize the total students taught by each teacher!
Follow these steps:
Create a loop for teachers
for
loop blockAdd up student counts
Create a list to store totals
list
block and name it total_Students
Append totals to your list
append
blocktotal_Students
listCreate a bar chart
pygal.Bar()
blockAdd data to the chart
add
block to add each teacher's name and total to the chartRender your chart
render
block:bulb: Having Trouble?
- Make sure your loops are properly nested (one inside the other where needed)
- Check that you're adding ALL time slots for each teacher
- Remember: lists in Python start at position 0, not 1!
Your chart should look like this:
Now let's practice incrementing variables - it's like adding points to your game score!
Follow these steps:
Create your starting score
variable
blockscore
100
Print the starting score
print
blockscore
variableAdd 300 points to your score
+=
)score
variablePrint the new score
print
blockscore
variable againAdd another 300 points
+=
)score
variablePrint the final score
print
blockscore
variable:bulb: Python Connection!
In real Python,
score += 300
is the same asscore = score + 300
. The+=
is just a shortcut that programmers love to use!
Your output should look like this:
Chart not showing?
render
block at the endNumbers look wrong?
Score not incrementing?
+=
block, not the regular =
blockscore
Ready for some extra challenges? Try these:
Color your chart!
Add chart labels
Score multiplier challenge
Compare teachers
Before submitting, make sure you have:
total_Students
list created and filledWhen you've completed both parts of your "Interactive Data Visualization with Pygal" activity:
:bulb: Before You Submit!
- Test your bar chart - does it show all teachers?
- Run your score program - do you see 100, 400, 700?
- Save your work one more time!
- You need to submit 2 project links - one for each part
Great job creating data visualizations! You're becoming a real data scientist! :star2: