D. The sales list has fewer values than the products list
Solution
Step 1: Check lengths of inputs
Products has 3 items, sales has 2 items; lengths must match for plt.bar().
Step 2: Understand error cause
Mismatch causes ValueError because matplotlib can't pair categories with missing values.
Final Answer:
The sales list has fewer values than the products list -> Option D
Quick Check:
Equal lengths needed for categories and values [OK]
Hint: Ensure categories and values lists have same length [OK]
Common Mistakes:
Thinking plt.bar() can't use string categories
Forgetting plt.show() causes no plot but no error
Assuming numeric categories are required
5. You have sales data for four stores: Store A (100), Store B (150), Store C (90), Store D (150). You want to create a bar chart comparing these stores but want to highlight stores with the highest sales in a different color. How can you do this in matplotlib?
hard
A. Use plt.bar() with a color list that sets a different color for stores with sales 150
B. Use plt.plot() to draw lines connecting sales values
C. Use plt.bar() but set all bars to the same color
D. Use plt.scatter() with sales as x and stores as y
Solution
Step 1: Identify highest sales values
Stores B and D have the highest sales (150).
Step 2: Create color list for bars
Assign a special color (e.g., red) to bars for sales 150, and default color for others.
Step 3: Use plt.bar() with colors
Pass the color list to plt.bar() to highlight highest sales bars.
Final Answer:
Use plt.bar() with a color list that sets a different color for stores with sales 150 -> Option A
Quick Check:
Color list highlights categories by value [OK]
Hint: Use color list in plt.bar() to highlight specific bars [OK]
Common Mistakes:
Using plt.plot() which makes line charts, not bars
Setting all bars same color loses highlight
Using plt.scatter() which is for points, not bars
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.