# 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:

#### Knowledge Organiser

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.

## Investigate

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

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

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

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

#### Help

Use the flowcharts if you need more support in understanding the steps required to meet the criteria. Use the Parsons code sorting exercise only if you are really stuck.

## Evaluate

Run your code to check that your program has met the success criteria and produces the required output.

Days with no rain: 6

Average rainfall: 0.12

Highest rainfall: 0.4

Registered in England and Wales: 10442992

VAT Number: 290 9845 58

Telephone: 01452 947500