Hello friends!!!!!
Problem of the Day
PYTHON
11/2/20241 min read
'''
Problem
A list contains the average daily temperature(in degree Celsius) of a city over a particular week.
Write a Python code to swap the highest and the lowest temperatures
a) A list containing average daily temperature over a week
temperatures = [34, 40, 29, 33, 42, 37, 39 ]
b) The expected output
c)Store the highest temperature
d) Index of the element with the highest temperature
max_temp_index =
e) Store the lowest temperature
min_temp =
f) Index of the element with the lowest temperature
min_temp_index =
'''
# list of the temperatures
temperatures = [34,40,29,33,42,37,39]
#to find maximum temperature
max_temp = max(temperatures)
print(f"Value of highest temperature is {max_temp}")
a = temperatures.index(max_temp)
print(f"Index of max temperture is {a}")
#to find lowest temperature
min_temp = min(temperatures)
print(f"Value of highest temperature is {min_temp}")
b = temperatures.index(min_temp)
print(f"Index of max temperture is {b}")
#to swap the highest and lowest temperatures
temp = max_temp
max_temp = min_temp
min_temp = temp
print(f"After swapping highest temperature is {max_temp} & minimum temperature is {min_temp}")
Output:
Value of highest temperature is 42
Index of max temperture is 4
Value of highest temperature is 29
Index of max temperture is 2
After swapping highest temperature is 29 & minimum temperature is 42