Rainfall

Rainfall

Analysing precipitation data.

Try


Select the button below to open the Python program in a new window. Run the program and read the lines of code to see if you can understand how it works. It will be helpful to arrange your display so that you can have this browser window on one side of the screen and the code on the other.

Watch this video to learn about the new concepts shown in the program:

Investigate


Questions to think about with this program to check your understanding:

Purpose question

What is the purpose of `value` in the function `count1`?

REVEAL ANSWER

`value` holds one item of data from the list in each iteration.

Reason question

Explain why a for loop has been used in the procedure `count2` instead of the while loop shown below:


def count3(item, data):

count = 0

index = 0

while item != data[index]:

if item == data[index]:

count = count + 1

index = index + 1

return count

REVEAL ANSWER

The while loop will stop as soon as the first data item is found. A for loop will iterate through all the items.


`while` is useful if you want to find the first instance of an item in a list and then stop. `for` is useful if you need to consider all the items in a list.

Make


Success Criteria

Change the program so that:

Both `analyse1` and `analyse2` functions:

  1. Calculate the average rainfall from the data.
  2. Calculate the highest rainfall in one day. I.e. the highest number in the data set.
  3. Return a list of count, average and highest.
  4. The main program outputs the three values with average rainfall to two decimal places.


You should apply your changes to both functions to illustrate the two different approaches.

Typical inputs and outputs from the program would be:

Days with no rain: 6

Average rainfall: 0.12

Highest rainfall: 0.4

Knowledge Organiser

Use these resources to learn about new commands for this level and to help you meet the success criteria.

Notes:

for x in y

Iterates over all the items in list y, with x being assigned to the data of each element one at a time in each iteration.

E.g. if `y = [“Hello”, “World”]` then x would be `”Hello”` in the first iteration and `”World”` in the second iteration.


for x in range(len(y))

Iterates over all the items in list y, with x being assigned the index of each element in the list in each iteration.

E.g. if `y = [“Hello”, “World”]` then x would be 0 in the first iteration and 1 in the second iteration.

Evaluate


Run the unit tests below to check that your program has met the success criteria.

Days with no rain: 6

Average rainfall: 0.12

Highest rainfall: 0.4

Craig'n'Dave logo

Craig ‘n’ Dave

In partnership with

Mission Encodeable
Bett Awards 2024 Finalist