{ "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": "b2306971-5bd6-45b6-a7de-fc6c723802dd", "cell_type": "markdown", "source": "
\n
Y7 – Spring 1 – Lesson 2: While Loops for Validation
\n
\n\n
", "metadata": {} }, { "id": "92f1c668-b526-41c8-90cc-eb1adbd70b82", "cell_type": "markdown", "source": "
\n

🕛 Do Now: Fix the Code

\n
\n\n
", "metadata": {} }, { "id": "1cd7e576-81b9-418f-b531-cf42c54f20be", "cell_type": "code", "source": "# Do Now – Fix the Code\nwhile true:\n guess = input(\"Name the most abundant gas in the atmosphere\")\n\n if guess.lower() = \"nitrogen\":\n print(\"Correct\")\n else:\n print(\"Incorrect\")\n\n#====> Describe the three errors and how you fixed them\n# (1)\n#\n# (2)\n#\n# (3)\n#", "metadata": {}, "outputs": [], "execution_count": null }, { "id": "b352fd1e-fe32-4c6e-9ad5-f3b1bd4319bf", "cell_type": "markdown", "source": "
\n

🎓 Coding Activity 1: Password Length Check

\n
\n
    \n
  1. Ask the user to enter a password
  2. \n
  3. Use a while loop to check the password length
  4. \n
  5. Repeat until the password is at least 8 characters long
  6. \n
\n
", "metadata": {} }, { "id": "c69aabe0-f45a-4044-89f9-c7c0e3ab9004", "cell_type": "code", "source": "# 🐍 Activity 1 – Password Length Validation\n\npassword = input(\"Enter a password: \")\n\n#====> Write your while loop here\n\n\nprint(\"Password accepted\")", "metadata": {}, "outputs": [], "execution_count": null }, { "id": "3e74764e-1cd0-48ac-b9c2-36f40ede7817", "cell_type": "markdown", "source": "
\n

🎓 Coding Activity 2: Email Presence Check

\n
\n
    \n
  1. Ask the user for an email address
  2. \n
  3. Check the email contains the @ symbol
  4. \n
  5. Repeat until valid input is entered
  6. \n
\n
", "metadata": {} }, { "id": "34d9ffba-86a4-4f9a-b499-458e329546be", "cell_type": "code", "source": "# 🐍 Activity 2 – Email Validation\n\nemail = input(\"Enter your email address: \")\n\n#====> Write your while loop here\n\n\nprint(\"Email accepted\")", "metadata": {}, "outputs": [], "execution_count": null }, { "id": "53da49c5-f497-484b-a0e0-46a981f8b678", "cell_type": "markdown", "source": "
\n

🎓 Coding Activity 3: Type Check – Age Validation

\n
\n
    \n
  1. Ask the user to enter their age
  2. \n
  3. Check the input is an integer
  4. \n
  5. Repeat until valid input is entered
  6. \n
\n
", "metadata": {} }, { "id": "24d18f3e-0f95-4701-a109-c1d6dfd9fb9a", "cell_type": "code", "source": "# 🐍 Activity 3 – Type Check\n\nage = input(\"Enter your age: \")\n\n#====> Write your while loop here\n# Hint: use isnumeric() or try/except\n\n\n\nprint(\"Age accepted\")", "metadata": { "trusted": true }, "outputs": [], "execution_count": null }, { "id": "55c0416d-2d82-46e1-a1b5-bfc84b3f1121", "cell_type": "markdown", "source": "
\n

🐍 Extension: Limiting Attempts

\n
\n
    \n
  1. Add an attempts variable
  2. \n
  3. Limit the user to three attempts
  4. \n
  5. Output \"Out of attempts\" and stop the program
  6. \n
\n
", "metadata": {} }, { "id": "5776378a-3d46-4763-b411-dae9cb974022", "cell_type": "markdown", "source": "
\n

🐍 Extension 2: Advanced Email Validation

\n
\n\n
", "metadata": {} } ] }