Skip to main content

Python Refresher — Lab

Pre-course reading

NotebookColabDownload
ExercisesOpen in Colab.ipynb
SolutionsOpen in Colab.ipynb

Open the Exercises notebook in Colab (or download it and run it locally), replace every ... with your code, and compare your results with the ✅ Check values given at the end of each exercise. Use plain Python only: NumPy comes in Week 1.

Before you finish

Run Runtime → Restart and run all. If the notebook runs from top to bottom without errors and your values match the checks, you're ready for Week 1.

Exercises​

#ExercisePython skillsLecture sections
1Flow in a pipevariables, arithmetic, f-strings, if / elif§2, §4
2A month of rainfalllists, comprehensions, for loops with counters§3, §4
3Gauging stationsdictionaries, list of dicts, max with key§3, §5
4Flow regimes along a spillwayfunctions, default arguments, tuple unpacking§5
5Friction losses in a pipeiterative solution, returning several values§4, §5
6Cleaning sensor readingstry / except, raising ValueError§6
7Saving the clean datareading and writing files with with§8

1. Flow in a pipe​

Compute the flow area, velocity and Reynolds number of a pipe flow, print them with their units, and classify the flow as laminar, transitional or turbulent.

2. A month of rainfall​

From a month of daily rainfall, compute the total and the wettest day, count the rainy days, and find the longest dry spell.

3. Gauging stations​

Add the specific discharge (L/s/km²) to a list of station records, find the station with the largest value, sum the catchment areas, and build a lookup table by station code.

4. Flow regimes along a spillway​

Write froude() and regime() functions, then classify measured sections from the upstream channel to the stilling basin.

5. Friction losses in a pipe​

Solve the implicit Colebrook–White equation by fixed-point iteration, compare it with the explicit Swamee–Jain formula, and compute the Darcy–Weisbach head loss.

6. Cleaning sensor readings​

Turn a messy text export from a water-level logger into clean numbers, rejecting missing, erroneous and physically impossible values.

7. Saving the clean data​

Write the cleaned readings to a text file and read them back.