Practice and reinforce the concepts from Lesson 11
In this activity, you will:
Estimated time: 20-25 minutes
Import the package numpy with the short name np.
import numpy as np
Import stats function from package scipy.
from scipy import stats
Create lists for age and height with the following values:
age = [13,14,15,15,16,15,17]
height = [167,165,176,170,167,164]
Print both variables to verify your data:
print("Age =", age)
print("Height =", height)
Expected output:
Age = [13, 14, 15, 15, 16, 15, 17]
Height = [167, 165, 176, 170, 167, 164]
:bulb: Make sure your list values match exactly! Double-check the numbers before proceeding.
Step 4: Calculate Mean (4 minutes)
Find the mean for each variable using the mean() method:
- Calculate the mean using
np.mean()
- Round to 2 decimal places using
round()
- Print the results
Expected result:
outputMean for age: 15.0 Mean for height: 168.17
tip Remember to use
np.mean()
from NumPy, not Python's built-in functions!
Find the median for each variable:
np.median()
methodExpected result:
Median for age: 15.0
Median for height: 167.0
Find the mode for each variable:
stats.mode()
method.mode[0]
Expected result:
Mode for age: 15
Mode for height: 167
:bulb: Tip The
stats.mode()
function returns an object. Use.mode[0]
to get just the mode value!
Common Issues:
numpy
and scipy.stats
correctly.mode[0]
to access the mode value from the result object:information_source: Important: Submit Your Work Before submitting:
- Review all your code and outputs
- Make sure all 6 steps are complete
- Verify your results match the expected outputs
- Save your Colab notebook
Ready to submit?
:link: Submit your exercise hereYour submission helps track your learning progress!