CBSE Class 11 Computer Science Question 51 of 63

Introduction to Python Modules — Question 20

Back to all questions
20
Question

Question 20

Consider the temperature given below for the month of June in North India. Calculate the average temperature and median value. This temperature gets dipped with a variation of 20°C in the month of December. Write a Python program to calculate the changed median value and average temperature.

LocationTemperature (in °C)
Delhi41
Shimla32
Chandigarh43
Rohtak40
Srinagar28
Sri Ganganagar45
Solution
import statistics
temp_jun = [41, 32, 43, 40, 28, 45]
avg_jun = statistics.mean(temp_jun)
median_jun = statistics.median(temp_jun)

temp_dec = []
for temp in temp_jun:
    temp_dec.append(temp - 20)

avg_dec = statistics.mean(temp_dec)
median_dec = statistics.median(temp_dec)
print("June - Average Temperature:", avg_jun)
print("June - Median Temperature:", median_jun)
print("December - Average Temperature:", avg_dec)
print("December - Median Temperature:", median_dec)
Output
June - Average Temperature: 38.166666666666664
June - Median Temperature: 40.5
December - Average Temperature: 18.166666666666668
December - Median Temperature: 20.5
Answer