A weather station records 10 temperatures each day.
Write a program that:
• asks the user to enter 10 temperatures and stores them in an array
• calculates and outputs the mean temperature
• outputs how many temperatures are above 20.
Use OCR Exam Reference Language or a high-level programming language. [6]
- Declares / initialises an array or list to hold the temperatures, e.g.
array temps[10]; allowtemps = []with append in Python(1) - Uses a loop that runs exactly 10 times to input values (e.g. for i = 0 to 9; for i in range(10)); allow a condition-controlled loop with a counter that is correctly updated so it runs 10 times(1)
- Stores each input in the array (at the loop index or by append); ignore whether or not the input is cast to real/int(1)
- Calculates the mean correctly: running total (or sum of the array) divided by 10 / the array length(1)
- Counts the values strictly greater than 20; allow in the same loop or a separate loop(1)
- Outputs both the mean and the count, once each (after the loop)(1)
- Answer:
array temps[10] total = 0 above = 0 for i = 0 to 9 temps[i] = float(input("Enter temperature")) total = total + temps[i] if temps[i] > 20 then above = above + 1 endif next i print("Mean: " + str(total / 10)) print("Above 20: " + str(above)) - Examiner tip: 'Above 20' means > 20, not >= 20. Also, the outputs go after the loop, or they will be printed ten times.