{ "metadata": { "kernelspec": { "name": "python", "display_name": "Python (Pyodide)", "language": "python" }, "language_info": { "codemirror_mode": { "name": "python", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8" } }, "nbformat_minor": 5, "nbformat": 4, "cells": [ { "id": "f8e4f675-bf4e-48c1-8bc3-974524499e46", "cell_type": "markdown", "source": "
\n
Y9 - Spring 1 - Lesson 2: Two-Dimensional Lists
\n
\n\n
", "metadata": {} }, { "id": "20363cd8-bbd3-4ad0-9f3f-f50afd84fa26", "cell_type": "markdown", "source": "
\n

🕛 Do Now: Fix the Code

\n
\n\n
", "metadata": {} }, { "id": "59331c19-7839-4889-997b-ebe7f7a5318b", "cell_type": "code", "source": "#⏱️ Do Now\n# This code should output each space fact\n\nspace_facts = [\"Black holes\", \"Supernovae\", \"Exoplanets\" \"Nebulae\", \"Pulsars\"]\n\nfor i in range(1,5):\n print(space_facts[each])\n\n#====> Describe the three errors below\n# (1)\n# (2)\n# (3)\n", "metadata": {}, "outputs": [], "execution_count": null }, { "id": "bf397247-d049-492c-b009-848b716145b7", "cell_type": "markdown", "source": "


\n
\n

🐍 Coding Activity 1: Introducing 2D Lists

\n
\n

Each menu item below has:

\n\n

Your teacher will demonstrate how to access items from a record (a list within a list):

\n

It will look like this

\n
Allergy advice: bread contains gluten
\n
\n

Following this you will learn how to output parts of each record to display each allergen

\n

To do this, you will use a for i in range() sequence

\n
Allergy advice: bread contains gluten
\n
Allergy advice: yogurt contains lactose
\n
Allergy advice: nutella contains hazelnut
\n
Allergy advice: cheese contains dairy
\n
Allergy advice: pasta contains gluten
\n
", "metadata": {} }, { "id": "eddf21a1-fd0e-45da-bbb5-c3c756174dcd", "cell_type": "code", "source": "#🐍 Activity 1 – Working with a 2 dimensional list\n\nmenu = [\n [\"bread\", \"gluten\"],\n [\"yogurt\", \"dairy\"],\n [\"nutella\", \"hazelnut\"],\n [\"cheese\", \"dairy\"],\n [\"pasta\", \"gluten\"]\n]\n\n#====> Output the first item of the second record\n\n\n#====> Output the second item of the second record\n\n\n#====> Output the items in one of the records as a statement\n#====> e.g. Allergy Advice: nutella contains hazelnut\n\n\n#====> Use a for i in range(): loop to output the same statement for each item in the list\n\n\n\n#------------------------------------------------------------------\n# Questions\n#------------------------------------------------------------------\n# (1) What do we call each list inside of a list? \n\n# (2) What does the first set of square brackets represent?\n\n# (3) What does the second set of square brackets represent?\n\n\n\n", "metadata": { "trusted": true }, "outputs": [], "execution_count": 1 }, { "id": "a9f79e0c-e81c-4eaa-ba35-0d9afbd68741", "cell_type": "markdown", "source": "


\n
\n

🐍 Coding Activity 2: Outputting items from a 2D list

\n
\n

You will now learn (with your teacher) how to use a for i in range(): loop to output each item in the list as part of this statement.

\n
\nShakespeare is a topic in the English curriculum\nAlgebra is a topic in the Maths curriculum\nPoetry analysis is a topic in the English curriculum\nSimultaneous equations is a topic in the Maths curriculum\nRivers and flooding is a topic in the Geography curriculum\nPopulation growth is a topic in the Geography curriculum\n
\n
", "metadata": {} }, { "id": "7d226735-773f-40e9-9f84-33ac75c03ed0", "cell_type": "code", "source": "#🐍 Activity 2 – Output items from records in a list\n\ntopics = [\n [\"Shakespeare\", \"English\"],\n [\"Algebra\", \"Maths\"],\n [\"Poetry analysis\", \"English\"],\n [\"Simultaneous equations\", \"Maths\"],\n [\"Rivers and flooding\", \"Geography\"],\n [\"Population growth\", \"Geography\"]\n]\n\n#====> Use a for i in range(): loop to output a statement that gives each topic and its subject\n#====> e.g. Shakespeare is a topic in the English curriculum.\n\n\n\n", "metadata": { "trusted": true }, "outputs": [], "execution_count": null }, { "id": "ded2aa5b-765f-49e0-bdaf-d73ade371fdd", "cell_type": "markdown", "source": "


\n
\n

🐍 Coding Activity 3: Searching Dietary Requirements

\n
\n

Create a program that will:

\n
    \n
  1. Ask the user for an allergen
  2. \n
  3. Iterate through the 2D list
  4. \n
  5. Tell the user which items they should avoid
  6. \n
\n

It will work like this

\n
\nEnter an allergen:  gluten\nYou should avoid the following:\nbread\npasta\n
\n
", "metadata": {} }, { "id": "8ae87279-83d8-41cd-a561-afe4fc48304d", "cell_type": "code", "source": "#🐍 Activity 3 – Allergen Checker\n\nmenu = [\n [\"bread\", \"gluten\"],\n [\"milk\", \"dairy\"],\n [\"nutella\", \"hazelnut\"],\n [\"cheese\", \"dairy\"],\n [\"pasta\", \"gluten\"]\n]\n\nallergen = input(\"Enter an allergen: \")\n\nprint(\"You should avoid the following:\")\n\n#====> Write your loop and selection below\n\n\n", "metadata": { "trusted": true }, "outputs": [], "execution_count": null }, { "id": "539c241d-0404-4a02-904e-3905681451eb", "cell_type": "markdown", "source": "


\n
\n

🐍 Coding Activity 4: Searching Student Records

\n
\n

Each student record contains:

\n\n

The program should ask for a grade and output students with that grade e.g.

\n
Name: Maya  | Mark: 51 | Grade: 8
\n
Name: Priya | Mark: 52 | Grade: 8
\n
Name: Emily | Mark: 50 | Grade: 8
\n
Name: Zara  | Mark: 54 | Grade: 8
\n
", "metadata": {} }, { "id": "b44f9583-23e4-486b-b438-0408b6ac7e8f", "cell_type": "code", "source": "#🐍 Activity 4 – Student Grades (2D List)\n\nstudents = [\n [\"Alex\", 48, \"7\"], [\"Priya\", 52, \"8\"], [\"James\", 34, \"5\"],\n [\"Sophie\", 56, \"9\"], [\"Liam\", 41, \"6\"], [\"Aisha\", 47, \"7\"],\n [\"Daniel\", 29, \"4\"], [\"Emily\", 50, \"8\"], [\"Noah\", 38, \"5\"],\n [\"Hannah\", 45, \"7\"], [\"Ben\", 33, \"5\"], [\"Zara\", 54, \"8\"],\n [\"Omar\", 27, \"4\"], [\"Chloe\", 49, \"7\"], [\"Leo\", 42, \"6\"],\n [\"Maya\", 51, \"8\"], [\"Ethan\", 36, \"5\"], [\"Amelia\", 58, \"9\"],\n [\"Jack\", 40, \"6\"], [\"Nina\", 46, \"7\"]\n]\n\ngrade = input(\"Enter a grade to search for: \")\n\nprint(\"Students with this grade:\")\n\n#====> Write your loop and selection below\n\n", "metadata": {}, "outputs": [], "execution_count": null }, { "id": "7b0efe58-faad-4906-bb59-4c1a72046e8e", "cell_type": "markdown", "source": "

\n
\n

🔴 Extension 1: Above or Below a Mark

\n
\n

Modify your program so the user can search for students:

\n\n
", "metadata": {} }, { "id": "f6c2eefc-ee92-4d02-9d4a-9ba7b3418a95", "cell_type": "code", "source": "#🔴 Extension 1 – Marks Filter\n\nmark = int(input(\"Enter a mark: \"))\nchoice = input(\"Above or below? \")\n\n#====> Your code below\n\n", "metadata": {}, "outputs": [], "execution_count": null }, { "id": "a54c9b32-3e0d-49a7-90bf-de3db533a074", "cell_type": "markdown", "source": "

\n
\n

🔴 Extension 2: Counting Grades

\n
\n

Count how many students achieved each grade.

\n

Hints:

\n\n
", "metadata": {} }, { "id": "c375da93-c8e4-4500-97e9-1fe40739fa19", "cell_type": "code", "source": "#🔴 Extension 2 – Count Grades\n\n#====> Your code below\n\n", "metadata": {}, "outputs": [], "execution_count": null } ] }