{ "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": "80c19b23-b438-47c9-a982-1b0ab88dae87", "cell_type": "markdown", "source": "
\n
Y7 - Spring 1 - Lesson 1: While Loops
\n
\n\n
", "metadata": {} }, { "id": "2c1b9716-5a5d-45b1-ae1a-7c8f5c548fb1", "cell_type": "markdown", "source": "
\n

🕛   Do Now: Fix The Code Below

\n\n
\n\n
\n
    \n
  • There are three errors in the code below
  • \n
  • Identify what they are and fix them
  • \n
  • Expain the changes you made in the comments section
  • \n
\n
", "metadata": {} }, { "id": "b3185f4a-1f26-40a0-b0a5-d7c709a76de3", "cell_type": "code", "source": "# Do Now\nnum1 = input(\"Enter the first number\")\nnum2 = input(\"Enter the second number\")\n\nanswer = num1 X num2\n\nprint(f\" {num1} X {num2} = answer\")\n\n#====> Describe the three errors and what you did to fix them\n#(1)\n#\n#(2)\n#\n#(3)\n#", "metadata": { "trusted": true }, "outputs": [], "execution_count": null }, { "id": "8acd9fa7-63cc-476c-9223-7f269838b81b", "cell_type": "markdown", "source": "
\n
\n
\n
\n
\n

🎓 Teacher Led - Coding Activity (A): Creating a While Loop

\n\n
\n\n
\n\n

In this activity, you will work on producing similar code to your teacher:

\n

The code will:

\n\n
    \n
  1. Ask the user to guess which shape the computer is thinking of
  2. \n
  3. Repeat the question if they answer incorrectly
  4. \n
  5. Congratulate them if they answer correctly
  6. \n
\n\n\n
\n
\n", "metadata": {} }, { "id": "afd1d001-3bab-4c8b-a708-8f3f6bdf168e", "cell_type": "code", "source": "# 🐍 Coding Activity A - While loops\n\nshape = \"triangle\"\n\n#====> Prompt the user to guess which shape the computer is thinking of\nguess = \n\n#====> While loop goes here\n\n\n\n#====> Output given when the user guesses correctly\n\n\n", "metadata": { "trusted": true }, "outputs": [], "execution_count": 1 }, { "id": "93fd2f05-f9b1-436f-af0f-b2507cb42b3f", "cell_type": "markdown", "source": "
\n
\n
\n
\n
\n

🎓  Teacher Led - Coding Activity (B): Using While True

\n\n
\n\n

Your teacher will now demonstrate how to use a While True Loop

\n

This will be combined with branching selection IF / ELIF / ELSE

\n
    \n
  1. Everything happens within a While Loop
  2. \n
  3. The program will ask the user to name a primary colour
  4. \n
  5. If they answer correctly it will congratulate them and the loop breaks
  6. \n
  7. If they answer incorrectly the loop will repeat again
  8. \n
\n\n
", "metadata": {} }, { "id": "09d38f71-d6df-45e2-be5c-bc922241317a", "cell_type": "code", "source": "# 🐍 Coding Activity B - While True Loops\n\n\n\n\n\n", "metadata": { "trusted": true }, "outputs": [], "execution_count": 1 }, { "id": "8fa663f0-45ed-4dae-abff-c29e283d1d0d", "cell_type": "markdown", "source": "
\n
\n
\n
\n
\n

🐍  Coding Activity (C): Using While True with Branching Selection

\n\n
\n\n
\n

Create a program that uses a While True Loop with branching selection:

\n
    \n
  1. Everything runs within a While True loop
  2. \n
  3. It asks the user to name a four sided shape (you can research these)
  4. \n
  5. A branching selection sequence checks if they have answered correctly
  6. \n
  7. If they have answered correctly the user is congratulated and the loop breaks
  8. \n
  9. If they have answered incorrectly the loop starts again
  10. \n
\n\n
", "metadata": {} }, { "id": "aeb05287-7b7c-4796-bd75-26e34227dc54", "cell_type": "code", "source": "# Coding Activity C - Using Range to Output Personalities\n\n\n\n", "metadata": { "trusted": true }, "outputs": [], "execution_count": null }, { "id": "f505694b-f9e6-43bf-9b1c-73301e1fa6d8", "cell_type": "markdown", "source": "
\n
\n
\n
\n

🐍  Extension: Updating Activity C

\n\n
\n\n

See if you can achieve any of the following:

\n
    \n
  1. Create a variable called attempts, and tell the user how many attempts they have had to get it right
  2. \n
  3. Using the attempts variable, use a selection IF / ELSE to test if attempts is greate than 3. If it is, output \"Out of Attempts and break the loop
  4. \n
\n\n\n
", "metadata": {} } ] }