Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to set the colors of the pie chart slices.
Matplotlib
import matplotlib.pyplot as plt sizes = [15, 30, 45, 10] colors = [1] plt.pie(sizes, colors=colors) plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using shapes or numbers instead of color names.
Passing the sizes list as colors.
✗ Incorrect
The colors parameter expects a list of color names or codes. Option A provides valid color names.
2fill in blank
mediumComplete the code to add labels and set custom colors for the pie chart.
Matplotlib
import matplotlib.pyplot as plt sizes = [20, 25, 35, 20] labels = ['A', 'B', 'C', 'D'] colors = [1] plt.pie(sizes, labels=labels, colors=colors) plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using fewer colors than slices.
Using invalid color names or shapes.
✗ Incorrect
The colors list must match the number of slices and contain valid color names. Option B is correct.
3fill in blank
hardFix the error in the code to correctly set the pie chart colors.
Matplotlib
import matplotlib.pyplot as plt sizes = [10, 40, 30, 20] colors = ['red', 'blue', 'green'] plt.pie(sizes, colors=[1]) plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a colors list shorter than sizes list.
Passing sizes as colors.
✗ Incorrect
The colors list must have the same length as sizes. Option A fixes the error by adding a fourth color.
4fill in blank
hardFill both blanks to create a pie chart with exploded slices and custom colors.
Matplotlib
import matplotlib.pyplot as plt sizes = [25, 35, 20, 20] colors = [1] explode = [2] plt.pie(sizes, colors=colors, explode=explode) plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using explode values outside 0 to 1 range.
Mismatch between colors and sizes length.
✗ Incorrect
Option A sets custom colors, and option B explodes the first slice only.
5fill in blank
hardFill all three blanks to create a pie chart with labels, custom colors, and exploded slices.
Matplotlib
import matplotlib.pyplot as plt sizes = [30, 20, 25, 25] labels = [1] colors = [2] explode = [3] plt.pie(sizes, labels=labels, colors=colors, explode=explode) plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using fewer colors than slices.
Exploding all slices instead of one.
✗ Incorrect
Labels are set with option A, colors with option B (hex codes), and explode with option C to highlight the second slice.