A. plt.show() is missing and needed to display the plot.
B. The bins parameter should be an integer, not a string.
C. plt.hist() requires a color argument.
D. The values list contains invalid data types.
Solution
Step 1: Check bins parameter type
The bins argument must be an integer or sequence of numbers, not a string like 'five'.
Step 2: Verify other parts
The data list is valid, color is optional, and plt.show() is present, so no other errors.
Final Answer:
The bins parameter should be an integer, not a string. -> Option B
Quick Check:
Bins must be int or list, not string [OK]
Hint: Bins must be number, not text [OK]
Common Mistakes:
Passing bins as a string instead of integer
Thinking color is required
Forgetting plt.show() (not the case here)
5. You have a dataset of exam scores ranging from 0 to 100. You want to create a histogram with 5 equal-width bins and color the bars blue. Which code snippet correctly achieves this?
hard
A. plt.hist(scores, bins=5, color='blue'); plt.show()
B. plt.hist(scores, bins=[0,20,50,70,90,100], color='blue'); plt.show()
C. plt.hist(scores, bins=5, colors='blue'); plt.show()
D. plt.hist(scores, bins=5, color=blue); plt.show()
Solution
Step 1: Use bins=integer for equal-width
bins=5 automatically divides the range (0-100) into 5 equal-width bins of 20 units each: [0-20, 20-40, 40-60, 60-80, 80-100].
Step 2: Color the bars blue
The color='blue' parameter sets the bar color correctly.
Step 3: Eliminate distractors
B specifies explicit bins [0,20,50,70,90,100] with unequal widths (20,30,20,20,10); C uses invalid 'colors'; D has unquoted 'blue' causing NameError.
Final Answer:
plt.hist(scores, bins=5, color='blue'); plt.show() -> Option A
Quick Check:
bins=5 (equal width) + color='blue' [OK]
Hint: bins=5 for equal-width over data range, color='blue' [OK]
Common Mistakes:
Using explicit bins with unequal widths
Using 'colors' instead of 'color'
Using color=blue without quotes
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.