Code Explanation:
Import the Library
import statistics as st
Imports Python’s built-in statistics library.
The alias st is used to make function calls shorter (ex: st.mean() instead of statistics.mean()).
Create a List of Data
data = [2, 4, 6, 8, 10]
A list named data is created containing five numeric values.
We will use this list to calculate statistical values.
Calculate the Mean (Average)
mean_val = st.mean(data)
st.mean(data) calculates the mean (average) of the list.
Mean formula = (2 + 4 + 6 + 8 + 10) / 5 = 30 / 5 = 6
The result is stored in the variable mean_val.
Calculate the Median (Middle Value)
median_val = st.median(data)
st.median(data) finds the median (middle number).
The sorted list is [2, 4, 6, 8, 10] — the middle value is 6
The result is stored in the variable median_val.
Print the Results
print(mean_val, median_val)
Prints both values in one line.
Output will be:
6 6
.png)

0 Comments:
Post a Comment