Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the matplotlib plotting module.
Matplotlib
import [1] as plt
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing the wrong library like numpy or pandas.
Forgetting to import pyplot specifically.
✗ Incorrect
We import the plotting module from matplotlib as plt to create charts.
2fill in blank
mediumComplete the code to create a pie chart from the data list.
Matplotlib
data = [30, 20, 50] plt.[1](data) plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'bar' or 'plot' instead of 'pie'.
Forgetting to call plt.show() to display the chart.
✗ Incorrect
The pie function creates a pie chart from the data.
3fill in blank
hardFix the error in the code to label the pie chart slices.
Matplotlib
sizes = [40, 35, 25] labels = ['A', 'B', 'C'] plt.pie(sizes, labels=[1]) plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the sizes list instead of labels.
Passing a string literal instead of the variable.
✗ Incorrect
The labels parameter should be set to the variable holding the labels list.
4fill in blank
hardFill both blanks to create a pie chart with percentages and a title.
Matplotlib
sizes = [10, 20, 70] labels = ['X', 'Y', 'Z'] plt.pie(sizes, labels=[1], autopct=[2]) plt.title('My Pie Chart') plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing sizes instead of labels for labels parameter.
Using incorrect format strings for autopct.
✗ Incorrect
Use the labels variable for labels and '%1.1f%%' to show percentages with one decimal.
5fill in blank
hardFill all three blanks to create a pie chart with labels, explode effect, and shadow.
Matplotlib
sizes = [15, 30, 55] labels = ['Red', 'Blue', 'Green'] explode = ([1], [2], [3]) plt.pie(sizes, labels=labels, explode=explode, shadow=True) plt.show()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using integers like 1 which offset too much.
Not using a tuple for explode.
✗ Incorrect
The explode tuple offsets the first slice by 0.1 and leaves others unchanged with 0.