Bird
0
0

Identify the error in this code snippet for plotting a pie chart on Raspberry Pi:

medium📝 Debug Q14 of 15
Raspberry Pi - Display and Output
Identify the error in this code snippet for plotting a pie chart on Raspberry Pi:
import matplotlib.pyplot as plt
sizes = [10, 20, 30]
labels = ['A', 'B', 'C']
plt.pie(sizes, labels=labels)
plt.show()
AMissing plt.title() causes error
BNo error, code will run and show pie chart
Csizes list must be numpy array, not list
Dplt.pie() requires colors argument
Step-by-Step Solution
Solution:
  1. Step 1: Check pie chart function requirements

    The plt.pie() function accepts sizes as list and labels as list without error.
  2. Step 2: Verify optional parameters

    Title and colors are optional; missing them does not cause errors.
  3. Final Answer:

    No error, code will run and show pie chart -> Option B
  4. Quick Check:

    plt.pie() works with lists and labels [OK]
Quick Trick: Pie chart needs sizes and labels only, colors optional [OK]
Common Mistakes:
MISTAKES
  • Thinking title is mandatory
  • Believing sizes must be numpy arrays
  • Assuming colors argument is required

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes