A. bins parameter should be an integer, not a string
B. plt.hist() does not accept lists as data
C. plt.show() is missing
D. values list must be converted to numpy array first
Solution
Step 1: Check bins parameter type
bins must be an integer or sequence, not a string like 'five'.
Step 2: Verify other parts
plt.hist accepts lists, plt.show() is present, numpy array conversion is optional.
Final Answer:
bins parameter should be an integer, not a string -> Option A
Quick Check:
bins must be int or sequence [OK]
Hint: bins must be int or list, not string [OK]
Common Mistakes:
Passing bins as string causes error
Thinking plt.hist needs numpy array
Forgetting plt.show()
5. You have a dataset with ages: [22, 25, 29, 35, 40, 42, 45, 50, 55, 60]. You want to create a histogram with bins representing decades (20-29, 30-39, 40-49, 50-59, 60-69). Which bins parameter should you use in plt.hist() to get this grouping?
hard
A. [20, 30, 40, 50, 60, 70]
B. [20, 29, 39, 49, 59, 69]
C. [20, 25, 30, 35, 40, 45, 50, 55, 60, 65]
D. [21, 31, 41, 51, 61, 71]
Solution
Step 1: Define bin edges for decades
Bins edges must cover ranges: 20-29, 30-39, etc. Using edges [20, 30, 40, 50, 60, 70] creates intervals [20-30), [30-40), etc.
Step 2: Confirm bins cover all ages
These edges include all ages from 22 to 60 correctly in decade groups.
Final Answer:
[20, 30, 40, 50, 60, 70] -> Option A
Quick Check:
Bins edges = decade boundaries [OK]
Hint: Bins edges define intervals; use decade boundaries [OK]
Common Mistakes:
Using bin edges that exclude upper bounds
Using single values instead of edges
Misaligning bins with decade ranges
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.