Which statement correctly describes the main difference between a histogram and a bar chart?
Think about whether the data is continuous or categorical and how bars are placed.
Histograms group continuous data into bins with adjacent bars showing frequency. Bar charts show separate bars for categories.
What will be the output of this code snippet?
import matplotlib.pyplot as plt import numpy as np data = np.random.normal(0, 1, 1000) plt.hist(data, bins=5) plt.show()
Look at the function used: plt.hist and the bins parameter.
plt.hist creates a histogram with bars adjacent representing frequency counts in bins.
Given this data preparation code, what is the output of counts?
categories = ['A', 'B', 'C'] values = [10, 15, 7] counts = dict(zip(categories, values)) print(counts)
Think about what zip and dict do together.
zip pairs elements from two lists by position, then dict creates key-value pairs.
You see a plot with bars touching each other representing ranges of ages and their counts. What type of plot is this?
Bars touching usually mean continuous data grouped in bins.
Histograms show continuous data grouped in bins with adjacent bars.
What error does this code raise and why?
import matplotlib.pyplot as plt categories = ['X', 'Y', 'Z'] values = [5, 7] plt.bar(categories, values) plt.show()
Check if the lists passed to plt.bar have the same length.
plt.bar requires x and height lists to be the same length. Here, categories has 3 items but values has 2.