DS105 2025-2026 Autumn Term Icon

πŸ’» Week 03 Lab

Control Flow Practice with Real Data

Author

Dr Jon Cardoso-Silva

Published

09 December 2025

πŸ₯… Learning Goals

By the end of this lab, you should be able to: i) Collect data from an API and save to JSON files, ii) Read JSON data back into Python for analysis, iii) Use loops to process data systematically, iv) Use conditionals to categorize and filter data.

This lab builds directly on yesterday’s πŸ–₯️ W03 Lecture where you learned about file I/O and saw code patterns for working with JSON files. Today you’ll apply those patterns alongside your DataQuest knowledge of loops and conditionals to analyze real temperature data.

πŸ“‹ Preparation

  • Complete the πŸ“ W03 Practice (Terminal commands and DataQuest loops/conditionals)
    • You should be comfortable with for loops and if/else statements
    • Your notes on DataQuest lessons will be essential today
  • Review the πŸ–₯️ W03 Lecture slides on JSON file I/O
    • You’ll adapt those code patterns today
  • Ensure you can access Nuvolos and launch VS Code: Using Nuvolos

πŸ›£οΈ Lab Roadmap

Part Activity Type Focus Time Outcome
Part 0 🎯 ACTION POINTS Setup & Preparation 5 min Download notebook + create data folder
Part I πŸ—£οΈ TEACHING MOMENT Catch Up & Revision 10 min Connect learning + revise loops & conditionals
Part II πŸ—£οΈ TEACHING MOMENT Code Demonstration 20 min Understand API β†’ JSON β†’ Read workflow
Part III 🎯 ACTION POINTS Control Flow Practice 40 min Create is_hot_day list independently
Wrap-Up πŸ—£οΈ TEACHING MOMENT Solution & W04 Setup 10-15 min Demonstrate solution + W04 Practice setup

πŸ’‘ What about Git? You will need to use your Git skills for your πŸ“ W04 Practice repository right after this lab. The focus of the lab itself, though, is to help you write code with loops and conditionals.

Part 0: Setup & Preparation (5 min)

Note to class teachers: Students complete this setup independently while you prepare for Part I. This gives them time to get organized and ensures everyone is ready for the teaching moments. Circulate to help with any technical issues.

Setup for Today:

  1. Download the notebook

    Use the button below to download the notebook we will use in this lab and save it to your week03/ folder in my-ds105a-notes.

  2. Create the data folder

    Open Terminal and run:

    cd /files/my-ds105a-notes/week03
    mkdir data
  3. Open the notebook

    Open the notebook in VS Code and get ready for Part I.

πŸ”— The Big Picture: Today you’ll bring together loops, conditionals, API calls, and file operations to analyze real temperature data. This is exactly the workflow you’ll use for W04 Practice!

Part I: Catch Up & Revision (10 min)

Note to class teachers: This is an interactive discussion to connect what students have learned across W01-W03. Gather from students what they’ve learned, help them see connections between Terminal, Python fundamentals, APIs, and file I/O. Then revise if-else and for loops with concrete examples before showing the notebook. This sets context for today’s work. Make it conversational and build on their responses.

Your class teacher will lead a discussion to connect everything you’ve learned so far and revise key concepts before today’s practical work.

Suggested Discussion Topics:

  • W01: What is data? Working with pandas to read CSV files and filter data
  • W02: APIs and how to collect data from the internet using requests.get()
  • W03 Practice: Terminal commands (cd, ls, pwd, mkdir) and DataQuest loops/conditionals
  • W03 Lecture: File systems, JSON file operations, and why we save data locally

Your teacher will now show you the notebook structure, help you catch up with the relevant programming concepts and explain what’s coming in Part II.

Part II: Code Demonstration (20 min)

Note to class teachers: Demonstrate Section 2 of the notebook line by line. Explain API requests, JSON file I/O, and nested data extraction. Students run code along with you. Focus on the complete workflow: API β†’ JSON save β†’ JSON load β†’ data extraction. Connect to W03 Lecture patterns.

Your class teacher will demonstrate Sections 1 and 2 of the notebook, explaining each line of code as you follow along and run it yourself.

What you’ll see:

  • API request to collect July 2024 temperature data
  • Saving data to JSON file (data/july_2024.json)
  • Reading the JSON file back into Python
  • Extracting dates and temperatures into separate lists

πŸ’‘ Why you should save data locally: Every time you send a request to an API, you are using up a limited resource. It is common for API servers to get overwhelmed and start rejecting requests. By saving the data locally, you collect it once and then work with it without relying on the availability of the API server.

Part III: Control Flow Practice (40 min)

Note to class teachers: Students work independently or in pairs on Part III of the notebook to create the is_hot_day list. Circulate to help with debugging. At the end, demonstrate the solution and connect to W04 Practice and W01 Lab.

🎯 ACTION POINTS

Write the relevant code to create a list called is_hot_day that categorises each day in July 2024 as True if temperature β‰₯ 28Β°C and False if temperature < 28Β°C.

πŸ’‘ Consult your πŸ“ W03 Practice notes to remind yourself of how to write code with loops and conditionals.


Wrap-Up & Next Steps (10-15 min)

Note to class teachers: Demonstrate your own is_hot_day solution, then point students to W04 Practice. If time allows, guide students through setting up W04 Practice repository; otherwise, remind them of the support sessions and point them to #help on Slack.

Your class teacher will demonstrate the solution and guide you through setting up πŸ“ W04 Practice due on Thursday 23 October, 12:00 GMT.

πŸ”— Useful Resources

πŸ“Š Essential Guides

πŸ’» Course Materials

  • πŸ—£οΈ W03 Lecture: File I/O demonstration and API patterns
  • πŸ“ W03 Practice: DataQuest loops and conditionals practice
  • πŸ“ W04 Practice: Your next task (due Thursday 23 October, 12:00 GMT)

πŸ†˜ Getting Help

  • Slack: Post questions to #help channel
  • Office Hours: Book via StudentHub
  • Self-Guided Practice: Fire up a new chat with our Custom AI assistant and type β€œTime for a challenge!”

Check staff availability on the βœ‹ Contact Hours page.

🌐 External Resources

πŸ“’ Remember: Your lab notebook has complete working code - use it as reference for your W04 Practice! The patterns you learned today will be essential for your next assignment.