Challenge - 5 Problems
Pie Chart Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this pie chart code?
Consider this Python code using matplotlib to create a pie chart. What will be the displayed percentages on the pie slices?
Matplotlib
import matplotlib.pyplot as plt sizes = [10, 20, 30] labels = ['A', 'B', 'C'] plt.pie(sizes, labels=labels, autopct='%1.1f%%') plt.show()
Attempts:
2 left
💡 Hint
Percentages are calculated as each size divided by the total sum of sizes.
✗ Incorrect
The total sum is 10 + 20 + 30 = 60. So, A is 10/60 = 16.7%, B is 20/60 = 33.3%, and C is 30/60 = 50%.
❓ data_output
intermediate1:30remaining
How many slices will the pie chart have?
Given this code snippet, how many slices will the pie chart display?
Matplotlib
import matplotlib.pyplot as plt sizes = [5, 15, 25, 55] plt.pie(sizes) plt.show()
Attempts:
2 left
💡 Hint
Each number in sizes corresponds to one slice.
✗ Incorrect
The list sizes has 4 numbers, so the pie chart will have 4 slices.
❓ visualization
advanced2:30remaining
Which option produces a pie chart with exploded slices?
Look at these four code snippets. Which one will create a pie chart where each slice is slightly separated (exploded) from the center?
Attempts:
2 left
💡 Hint
The explode parameter controls how far each slice is offset from the center.
✗ Incorrect
Only option C explodes all slices equally by 0.1, separating each slice from the center.
🔧 Debug
advanced2:00remaining
What error does this pie chart code raise?
This code tries to create a pie chart but fails. What error will it raise?
Matplotlib
import matplotlib.pyplot as plt sizes = [10, 20] labels = ['A', 'B', 'C'] plt.pie(sizes, labels=labels) plt.show()
Attempts:
2 left
💡 Hint
Labels list length must match sizes list length exactly.
✗ Incorrect
The labels list has 3 items but sizes has 2, causing a ValueError about mismatched lengths.
🚀 Application
expert2:30remaining
Which option produces a pie chart with a shadow and start angle at 90 degrees?
You want a pie chart that has a shadow effect and starts drawing slices from the top (90 degrees). Which code snippet does this correctly?
Attempts:
2 left
💡 Hint
The shadow parameter adds a shadow, startangle rotates the start position in degrees.
✗ Incorrect
Option A sets shadow=True for shadow and startangle=90 to start slices from the top.