Computer Science
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.
| Location | Temperature (in °C) |
|---|---|
| Delhi | 41 |
| Shimla | 32 |
| Chandigarh | 43 |
| Rohtak | 40 |
| Srinagar | 28 |
| Sri Ganganagar | 45 |
Answer
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
Related Questions
Write a Python program to generate a random number between 0 and 9.
Define a function which accepts n as an argument and prints Fibonacci series till n.
Create a menu-driven program using user-defined functions to implement a calculator that performs the following:
(a) Basic arithmetic operations (+, −, *, /)
(b) log10(x), sin(x), cos(x)
Write a program that contains user-defined functions to calculate area, perimeter or surface area whichever is applicable, for various shapes like square, rectangle, triangle, circle and cylinder. The user-defined functions should accept the values for calculation as parameters and the calculated value should be returned. Import the module and use appropriate functions.