Objective
Filter temperatures above 20 and calculate the average of that group only.
Remember how to code.
Foundations · Python
Variables, a collection, and one readable transformation.
Before the code · Python
Understand the problem first. Then rebuild the solution.
Name the data, transform it once, and make the intent visible. Read the whole expression before you begin.
temperatures = [18, 21, 24, 19, 27]
above_twenty = [value for value in temperatures if value > 20]
average = sum(above_twenty) / len(above_twenty)
print(f"Average: {average:.1f} Celsius")temperatures = [18, 21, 24, 19, 27]above_twenty = [value for value in temperatures if value > 20]average = sum(above_twenty) / len(above_twenty) print(f"Average: {average:.1f} Celsius")Filter temperatures above 20 and calculate the average of that group only.