Repository: francismontalbo/learning_python
Branch: main
Commit: 33ddb010fdfe
Files: 380
Total size: 195.0 KB
Directory structure:
gitextract_dimi7smm/
├── README.md
├── ppts/
│ ├── 0001 Introduction to Python.pptx
│ ├── 0002 Pyhton Data Structures Collections.pptx
│ ├── 0003 Conditions and if statements with Python.pptx
│ ├── 0004 Python Functions.pptx
│ ├── 0005 Recursion in Python.pptx
│ └── 0006 Python Exception and errors Try Except Else Finally.pptx
├── python_techniques.ipynb
├── sample_structure/
│ ├── main.py
│ └── src/
│ ├── mixins.py
│ └── number_guesser.py
├── week_1/
│ ├── 0001_practice_python_basics.ipynb
│ └── 0001_python_basics.ipynb
├── week_2/
│ ├── 0002_collections.ipynb
│ └── 0002_practice_collections.ipynb
├── week_3/
│ ├── 0003_Loops.ipynb
│ ├── 0003_ifelifelse.ipynb
│ ├── 0003_practice_control_flow.ipynb
│ ├── 0003_truthyandfalsies.ipynb
│ └── audio/
│ ├── BGM/
│ │ ├── Airship.ogg
│ │ ├── Battle1.ogg
│ │ ├── Battle2.ogg
│ │ ├── Battle3.ogg
│ │ ├── Battle4.ogg
│ │ ├── Battle5.ogg
│ │ ├── Battle6.ogg
│ │ ├── Battle7.ogg
│ │ ├── Battle8.ogg
│ │ ├── Battle9.ogg
│ │ ├── Dungeon1.ogg
│ │ ├── Dungeon2.ogg
│ │ ├── Dungeon3.ogg
│ │ ├── Dungeon4.ogg
│ │ ├── Dungeon5.ogg
│ │ ├── Dungeon6.ogg
│ │ ├── Dungeon7.ogg
│ │ ├── Dungeon8.ogg
│ │ ├── Dungeon9.ogg
│ │ ├── Field1.ogg
│ │ ├── Field2.ogg
│ │ ├── Field3.ogg
│ │ ├── Field4.ogg
│ │ ├── Scene1.ogg
│ │ ├── Scene2.ogg
│ │ ├── Scene3.ogg
│ │ ├── Scene4.ogg
│ │ ├── Scene5.ogg
│ │ ├── Scene6.ogg
│ │ ├── Ship.ogg
│ │ ├── Theme1.ogg
│ │ ├── Theme2.ogg
│ │ ├── Theme3.ogg
│ │ ├── Theme4.ogg
│ │ ├── Theme5.ogg
│ │ ├── Town1.ogg
│ │ ├── Town2.ogg
│ │ ├── Town3.ogg
│ │ ├── Town4.ogg
│ │ ├── Town5.ogg
│ │ ├── Town6.ogg
│ │ └── Town7.ogg
│ ├── BGS/
│ │ ├── Clock.ogg
│ │ ├── Darkness.ogg
│ │ ├── Drips.ogg
│ │ ├── Fire.ogg
│ │ ├── Quake.ogg
│ │ ├── Rain.ogg
│ │ ├── River.ogg
│ │ ├── Sea.ogg
│ │ ├── Storm.ogg
│ │ └── Wind.ogg
│ ├── ME/
│ │ ├── Fanfare1.ogg
│ │ ├── Fanfare2.ogg
│ │ ├── Fanfare3.ogg
│ │ ├── Gag.ogg
│ │ ├── Gameover1.ogg
│ │ ├── Gameover2.ogg
│ │ ├── Inn.ogg
│ │ ├── Item.ogg
│ │ ├── Mystery.ogg
│ │ ├── Organ.ogg
│ │ ├── Shock.ogg
│ │ ├── Victory1.ogg
│ │ └── Victory2.ogg
│ └── SE/
│ ├── Absorb1.ogg
│ ├── Absorb2.ogg
│ ├── Applause1.ogg
│ ├── Applause2.ogg
│ ├── Attack1.ogg
│ ├── Attack2.ogg
│ ├── Attack3.ogg
│ ├── Autodoor.ogg
│ ├── Barrier.ogg
│ ├── Battle1.ogg
│ ├── Battle2.ogg
│ ├── Battle3.ogg
│ ├── Bell1.ogg
│ ├── Bell2.ogg
│ ├── Bell3.ogg
│ ├── Bite.ogg
│ ├── Blind.ogg
│ ├── Blow1.ogg
│ ├── Blow2.ogg
│ ├── Blow3.ogg
│ ├── Blow4.ogg
│ ├── Blow5.ogg
│ ├── Blow6.ogg
│ ├── Blow7.ogg
│ ├── Blow8.ogg
│ ├── Book1.ogg
│ ├── Book2.ogg
│ ├── Bow1.ogg
│ ├── Bow2.ogg
│ ├── Bow3.ogg
│ ├── Bow4.ogg
│ ├── Break.ogg
│ ├── Breath.ogg
│ ├── Buzzer1.ogg
│ ├── Buzzer2.ogg
│ ├── Cancel1.ogg
│ ├── Cancel2.ogg
│ ├── Cat.ogg
│ ├── Chest.ogg
│ ├── Chicken.ogg
│ ├── Chime1.ogg
│ ├── Chime2.ogg
│ ├── Close1.ogg
│ ├── Close2.ogg
│ ├── Close3.ogg
│ ├── Coin.ogg
│ ├── Collapse1.ogg
│ ├── Collapse2.ogg
│ ├── Collapse3.ogg
│ ├── Collapse4.ogg
│ ├── Confuse.ogg
│ ├── Cow.ogg
│ ├── Crash.ogg
│ ├── Crossbow.ogg
│ ├── Crow.ogg
│ ├── Cry1.ogg
│ ├── Cry2.ogg
│ ├── Cursor1.ogg
│ ├── Cursor2.ogg
│ ├── Damage1.ogg
│ ├── Damage2.ogg
│ ├── Damage3.ogg
│ ├── Damage4.ogg
│ ├── Damage5.ogg
│ ├── Darkness1.ogg
│ ├── Darkness2.ogg
│ ├── Darkness3.ogg
│ ├── Darkness4.ogg
│ ├── Darkness5.ogg
│ ├── Darkness6.ogg
│ ├── Darkness7.ogg
│ ├── Darkness8.ogg
│ ├── Decision1.ogg
│ ├── Decision2.ogg
│ ├── Decision3.ogg
│ ├── Devil1.ogg
│ ├── Devil2.ogg
│ ├── Devil3.ogg
│ ├── Disappointment.ogg
│ ├── Dive.ogg
│ ├── Dog.ogg
│ ├── Down1.ogg
│ ├── Down2.ogg
│ ├── Down3.ogg
│ ├── Down4.ogg
│ ├── Earth1.ogg
│ ├── Earth2.ogg
│ ├── Earth3.ogg
│ ├── Earth4.ogg
│ ├── Earth5.ogg
│ ├── Earth6.ogg
│ ├── Earth7.ogg
│ ├── Earth8.ogg
│ ├── Earth9.ogg
│ ├── Equip1.ogg
│ ├── Equip2.ogg
│ ├── Equip3.ogg
│ ├── Evasion1.ogg
│ ├── Evasion2.ogg
│ ├── Explosion1.ogg
│ ├── Explosion2.ogg
│ ├── Explosion3.ogg
│ ├── Explosion4.ogg
│ ├── Explosion5.ogg
│ ├── Explosion6.ogg
│ ├── Explosion7.ogg
│ ├── Fall.ogg
│ ├── Fire1.ogg
│ ├── Fire2.ogg
│ ├── Fire3.ogg
│ ├── Fire4.ogg
│ ├── Fire5.ogg
│ ├── Fire6.ogg
│ ├── Fire7.ogg
│ ├── Fire8.ogg
│ ├── Fire9.ogg
│ ├── Flash1.ogg
│ ├── Flash2.ogg
│ ├── Flash3.ogg
│ ├── Fog1.ogg
│ ├── Fog2.ogg
│ ├── Frog.ogg
│ ├── Gun1.ogg
│ ├── Gun2.ogg
│ ├── Hammer.ogg
│ ├── Heal1.ogg
│ ├── Heal2.ogg
│ ├── Heal3.ogg
│ ├── Heal4.ogg
│ ├── Heal5.ogg
│ ├── Heal6.ogg
│ ├── Heal7.ogg
│ ├── Horse.ogg
│ ├── Ice1.ogg
│ ├── Ice10.ogg
│ ├── Ice11.ogg
│ ├── Ice2.ogg
│ ├── Ice3.ogg
│ ├── Ice4.ogg
│ ├── Ice5.ogg
│ ├── Ice6.ogg
│ ├── Ice7.ogg
│ ├── Ice8.ogg
│ ├── Ice9.ogg
│ ├── Item1.ogg
│ ├── Item2.ogg
│ ├── Item3.ogg
│ ├── Jump1.ogg
│ ├── Jump2.ogg
│ ├── Key.ogg
│ ├── Knock.ogg
│ ├── Laser.ogg
│ ├── Load.ogg
│ ├── Machine.ogg
│ ├── Magic1.ogg
│ ├── Magic2.ogg
│ ├── Magic3.ogg
│ ├── Magic4.ogg
│ ├── Magic5.ogg
│ ├── Magic6.ogg
│ ├── Magic7.ogg
│ ├── Miss.ogg
│ ├── Monster1.ogg
│ ├── Monster2.ogg
│ ├── Monster3.ogg
│ ├── Monster4.ogg
│ ├── Monster5.ogg
│ ├── Monster6.ogg
│ ├── Monster7.ogg
│ ├── Move.ogg
│ ├── Noise.ogg
│ ├── Open1.ogg
│ ├── Open2.ogg
│ ├── Open3.ogg
│ ├── Open4.ogg
│ ├── Open5.ogg
│ ├── Paralyze1.ogg
│ ├── Paralyze2.ogg
│ ├── Paralyze3.ogg
│ ├── Parry.ogg
│ ├── Phone.ogg
│ ├── Poison.ogg
│ ├── Pollen.ogg
│ ├── Powerup.ogg
│ ├── Push.ogg
│ ├── Raise1.ogg
│ ├── Raise2.ogg
│ ├── Raise3.ogg
│ ├── Recovery.ogg
│ ├── Reflection.ogg
│ ├── Resonance.ogg
│ ├── Run.ogg
│ ├── Saint1.ogg
│ ├── Saint2.ogg
│ ├── Saint3.ogg
│ ├── Saint4.ogg
│ ├── Saint5.ogg
│ ├── Saint6.ogg
│ ├── Saint7.ogg
│ ├── Saint8.ogg
│ ├── Saint9.ogg
│ ├── Sand.ogg
│ ├── Save.ogg
│ ├── Scream.ogg
│ ├── Sheep.ogg
│ ├── Shop.ogg
│ ├── Shot1.ogg
│ ├── Shot2.ogg
│ ├── Shot3.ogg
│ ├── Silence.ogg
│ ├── Skill1.ogg
│ ├── Skill2.ogg
│ ├── Skill3.ogg
│ ├── Slash1.ogg
│ ├── Slash10.ogg
│ ├── Slash11.ogg
│ ├── Slash12.ogg
│ ├── Slash2.ogg
│ ├── Slash3.ogg
│ ├── Slash4.ogg
│ ├── Slash5.ogg
│ ├── Slash6.ogg
│ ├── Slash7.ogg
│ ├── Slash8.ogg
│ ├── Slash9.ogg
│ ├── Sleep.ogg
│ ├── Sound1.ogg
│ ├── Sound2.ogg
│ ├── Sound3.ogg
│ ├── Stare.ogg
│ ├── Starlight.ogg
│ ├── Switch1.ogg
│ ├── Switch2.ogg
│ ├── Switch3.ogg
│ ├── Sword1.ogg
│ ├── Sword2.ogg
│ ├── Sword3.ogg
│ ├── Sword4.ogg
│ ├── Sword5.ogg
│ ├── Teleport.ogg
│ ├── Thunder1.ogg
│ ├── Thunder10.ogg
│ ├── Thunder11.ogg
│ ├── Thunder12.ogg
│ ├── Thunder2.ogg
│ ├── Thunder3.ogg
│ ├── Thunder4.ogg
│ ├── Thunder5.ogg
│ ├── Thunder6.ogg
│ ├── Thunder7.ogg
│ ├── Thunder8.ogg
│ ├── Thunder9.ogg
│ ├── Twine.ogg
│ ├── Up1.ogg
│ ├── Up2.ogg
│ ├── Up3.ogg
│ ├── Up4.ogg
│ ├── Water1.ogg
│ ├── Water2.ogg
│ ├── Water3.ogg
│ ├── Water4.ogg
│ ├── Water5.ogg
│ ├── Water6.ogg
│ ├── Wind1.ogg
│ ├── Wind10.ogg
│ ├── Wind11.ogg
│ ├── Wind2.ogg
│ ├── Wind3.ogg
│ ├── Wind4.ogg
│ ├── Wind5.ogg
│ ├── Wind6.ogg
│ ├── Wind7.ogg
│ ├── Wind8.ogg
│ ├── Wind9.ogg
│ └── Wolf.ogg
├── week_4/
│ ├── 0004_Functions.ipynb
│ └── 0004_practice_functions.ipynb
├── week_5/
│ ├── 0005 recursion.ipynb
│ └── 0005_practice_recursion.ipynb
├── week_6/
│ ├── 0006_practice_exceptions.ipynb
│ └── try_except.ipynb
├── week_7/
│ ├── 0007 Objects and Classes.ipynb
│ └── 0007_practice_oop_basics.ipynb
├── week_8/
│ ├── 0008 Inheritance Basics.ipynb
│ └── 0008_practice_inheritance.ipynb
├── week_9/
│ ├── 0009_practice_relationships.ipynb
│ ├── aggregation.ipynb
│ ├── association.ipynb
│ ├── composition.ipynb
│ └── mixin..ipynb
├── week_x/
│ ├── 0010_practice_oop_design.ipynb
│ ├── abstraction.ipynb
│ ├── encapsulation.ipynb
│ └── polymorphism.ipynb
└── week_x2/
├── 0011_practice_unit_testing.ipynb
└── unit_test.ipynb
================================================
FILE CONTENTS
================================================
================================================
FILE: README.md
================================================
# ⚔️ Becoming a Python Hero
**A notebook-driven Python journey for beginners who want to grow from curious learners into confident builders.**
> Learn slowly. Practice deeply. Write clean code. Build real confidence.
## 🚀 Why this repo hits differently
This repository is not meant to be a pile of random Python snippets. It is meant to feel like a guided adventure.
Inside these notebooks, students move from:
- printing their first line of Python
- to organizing data with collections
- to making decisions with conditions and loops
- to designing reusable functions
- to building object-oriented programs
- to testing their own code like real developers
The goal is not just to “finish Python.” The goal is to **think clearly, code professionally, and keep leveling up**.
## 🧠 What makes these notebooks useful
These lessons were shaped to be:
- **Gradual** — each notebook starts simple and grows carefully
- **Connected** — older topics return in newer lessons so they stay alive
- **Readable** — code examples favor clarity, naming, and structure
- **Practical** — examples are grounded, reusable, and beginner-safe
- **Encouraging** — the tone aims to motivate without watering things down
## 🗺️ Recommended learning path
### 1. Foundations
- `week_1/0001_python_basics.ipynb`
- `week_2/0002_collections.ipynb`
- `week_3/0003_ifelifelse.ipynb`
- `week_3/0003_truthyandfalsies.ipynb`
- `week_3/0003_Loops.ipynb`
- `week_4/0004_Functions.ipynb`
- `week_5/0005 recursion.ipynb`
- `week_6/try_except.ipynb`
### 2. Object-Oriented Python
- `week_7/0007 Objects and Classes.ipynb`
- `week_8/0008 Inheritance Basics.ipynb`
- `week_9/association.ipynb`
- `week_9/aggregation.ipynb`
- `week_9/composition.ipynb`
- `week_9/mixin..ipynb`
- `week_x/encapsulation.ipynb`
- `week_x/polymorphism.ipynb`
- `week_x/abstraction.ipynb`
### 3. Reinforcement and skill growth
- `week_x2/unit_test.ipynb`
- `python_techniques.ipynb`
## 🎯 Best way to use this repo
For each notebook:
1. read the markdown sections first
2. run every code cell in order
3. change at least one value in every major example
4. predict the output before running the next cell
5. write one tiny variation of your own before moving on
That is how you stop being a passive reader and start becoming a programmer.
## 🧩 Weekly practice notebooks
To help students build problem-solving stamina—not just topic familiarity—the repository now includes a dedicated practice notebook for each week grouping. These are designed for review, exam preparation, debugging practice, and job-style thinking.
- `week_1/0001_practice_python_basics.ipynb`
- `week_2/0002_practice_collections.ipynb`
- `week_3/0003_practice_control_flow.ipynb`
- `week_4/0004_practice_functions.ipynb`
- `week_5/0005_practice_recursion.ipynb`
- `week_6/0006_practice_exceptions.ipynb`
- `week_7/0007_practice_oop_basics.ipynb`
- `week_8/0008_practice_inheritance.ipynb`
- `week_9/0009_practice_relationships.ipynb`
- `week_x/0010_practice_oop_design.ipynb`
- `week_x2/0011_practice_unit_testing.ipynb`
A good rhythm is to finish the lesson notebook first, then immediately attempt the matching practice notebook while the ideas are still fresh.
## 🛠️ Tools you can use to open the notebooks
- Jupyter Notebook
- JupyterLab
- VS Code with the Jupyter extension
- Google Colab after uploading the files
Recommended Python version: **Python 3.9+**
## 🔥 What students should gain by the end
By working through the notebooks in order, learners should become much more comfortable with:
- reading Python code
- explaining what code is doing
- writing clean beginner-to-intermediate solutions
- spotting patterns worth turning into functions or classes
- testing ideas instead of guessing
- thinking like someone who can build projects, not just copy syntax
## 💥 Final message
You do **not** need to rush to become strong at Python.
You need repetition, curiosity, clean habits, and enough courage to keep editing your code when it does not work the first time.
If you stick with that, you will not just “learn Python.” You will build the mindset of a real programmer.
================================================
FILE: python_techniques.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Python Techniques\n",
"\n",
"This notebook collects a few useful intermediate techniques that build naturally on the earlier lessons.\n"
],
"id": "5b52b7de"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Learning goals\n",
"\n",
"You will practice:\n",
"- list comprehensions\n",
"- nested comprehensions\n",
"- helper functions used inside comprehensions\n",
"- using earlier ideas such as conditions, loops, and functions in compact forms\n"
],
"id": "f9d013f5"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## List comprehensions\n"
],
"id": "11b83790"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"numbers = list(range(1, 11))\n",
"even_squares = [number ** 2 for number in numbers if number % 2 == 0]\n",
"print(even_squares)\n"
],
"id": "68fd9a27"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## String-based comprehensions\n"
],
"id": "6a56d894"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fruit_names = [\"apple\", \"banana\", \"cherry\", \"fig\"]\n",
"name_lengths = [len(name) for name in fruit_names]\n",
"print(name_lengths)\n"
],
"id": "ad744537"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Filtering with a condition\n"
],
"id": "aea0888c"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"scores = [72, 85, 91, 68, 95]\n",
"strong_scores = [score for score in scores if score >= 80]\n",
"print(strong_scores)\n"
],
"id": "91f9d6dc"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Flattening a nested list\n"
],
"id": "ea4bd7a0"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"study_groups = [[\"Avery\", \"Jordan\"], [\"Riley\"], [\"Sam\", \"Taylor\"]]\n",
"all_students = [student for group in study_groups for student in group]\n",
"print(all_students)\n"
],
"id": "4258c38d"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## A helper function inside a comprehension\n"
],
"id": "1fc82c1e"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def is_prime(number):\n",
" if number <= 1:\n",
" return False\n",
" if number <= 3:\n",
" return True\n",
" if number % 2 == 0 or number % 3 == 0:\n",
" return False\n",
"\n",
" candidate = 5\n",
" while candidate * candidate <= number:\n",
" if number % candidate == 0 or number % (candidate + 2) == 0:\n",
" return False\n",
" candidate += 6\n",
" return True\n",
"\n",
"prime_numbers = [number for number in range(1, 50) if is_prime(number)]\n",
"print(prime_numbers)\n"
],
"id": "92b3aed9"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Dictionary comprehension\n"
],
"id": "967991e3"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"score_labels = {score: (\"pass\" if score >= 75 else \"review\") for score in scores}\n",
"print(score_labels)\n"
],
"id": "f7cfc340"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Practice prompts\n",
"\n",
"1. Build a list of cubes from 1 to 6.\n",
"2. Filter words by length using a comprehension.\n",
"3. Create a dictionary comprehension from a list of names.\n"
],
"id": "0dd297d7"
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
================================================
FILE: sample_structure/main.py
================================================
from src.number_guesser import NumberGuesser
def main():
print("Welcome to Number Guesser!")
game = NumberGuesser()
game.start()
if __name__ == "__main__":
main()
================================================
FILE: sample_structure/src/mixins.py
================================================
import os
class ScoreMixin:
def __init__(self, score_file):
self.score_file = score_file
def load_highest_score(self):
try:
with open(self.score_file, "r") as file:
return int(file.read())
except FileNotFoundError:
return None
except ValueError:
print("Error: Invalid data in score file.")
return None
def load_highest_score_date(self, score_file):
try:
with open(score_file, "r") as file:
return file.read()
except FileNotFoundError:
return None
================================================
FILE: sample_structure/src/number_guesser.py
================================================
import os
import random
from src.mixins import ScoreMixin
from datetime import datetime
class NumberGuesser(ScoreMixin):
def __init__(self):
self.data_folder = "data"
self.score_file = os.path.join(self.data_folder, "highest_score.txt")
self.highest_score_date_file = os.path.join(self.data_folder, "highest_score_date.txt")
super().__init__(self.score_file)
self.create_data_folder()
def create_data_folder(self):
if not os.path.exists(self.data_folder):
os.makedirs(self.data_folder)
def load_highest_score_date(self):
if os.path.exists(self.highest_score_date_file):
with open(self.highest_score_date_file, "r") as file:
return file.read()
return None
def save_highest_score_and_date(self, score, date):
try:
with open(self.score_file, "w") as file:
file.write(str(score))
with open(self.highest_score_date_file, "w") as file:
file.write(date)
except IOError:
print("Error: Unable to save score and date.")
def play_name_guesser(self):
secret_number = random.randint(1, 100)
attempts = 0
print("Try to guess the secret number between 1 and 100!")
print("Enter 'q' to quit.")
while True:
guess = input("Enter your guess: ")
if guess.lower() == 'q':
print("Quitting the game.")
break
if not guess.isdigit():
print("Please enter a valid number.")
continue
guess = int(guess)
attempts += 1
if guess < secret_number:
print("Too low! Try again.")
elif guess > secret_number:
print("Too high! Try again.")
else:
print(f"Congratulations! You guessed the number in {attempts} attempts.")
highest_score = self.load_highest_score()
highest_score_date = self.load_highest_score_date()
if highest_score is None or attempts < highest_score:
if highest_score is not None:
print(f"NEW RECORD! Previous Record: {highest_score} (Achieved on: {highest_score_date})")
current_datetime = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
self.save_highest_score_and_date(attempts, current_datetime)
else:
print(f"FAIL TO ACHIEVE NEW RECORD. CURRENT RECORD: {highest_score} (Achieved on: {highest_score_date})")
break
def display_menu(self):
print("\nMenu:")
print("1. Start Game")
print("2. View Highest Score")
print("3. Quit")
def start(self):
while True:
self.display_menu()
choice = input("Enter your choice: ")
if choice == '1':
self.play_name_guesser()
elif choice == '2':
highest_score = self.load_highest_score()
highest_score_date = self.load_highest_score_date()
if highest_score is not None:
print(f"Highest Score: {highest_score} (Achieved on: {highest_score_date})")
else:
print("No highest score recorded yet.")
elif choice == '3':
print("Exiting the game.")
break
else:
print("Invalid choice. Please try again.")
================================================
FILE: week_1/0001_practice_python_basics.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"id": "c6d04410",
"source": [
"# Week 1 Practice — Python Basics\n",
"\n",
"This practice notebook is designed to strengthen student thinking, not just student memory. The goal is to turn the week's lesson into repeatable skill.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "11f5ea16",
"source": [
"## Why this practice notebook matters\n",
"\n",
"In real jobs, developers are expected to do more than remember syntax. They must inspect data carefully, break problems into parts, explain their reasoning, and produce dependable solutions under pressure. These exercises are built to train those habits early.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "c2c01cc8",
"source": [
"## Focus areas\n",
"\n",
"- variables and data types\n",
"- arithmetic and type conversion\n",
"- strings and formatted output\n",
"- thinking carefully before coding\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "a53acfc9",
"source": [
"## How to use this notebook\n",
"\n",
"1. Solve the warm-up tasks first.\n",
"2. Write your own answer before looking for patterns.\n",
"3. Test small pieces of code often.\n",
"4. Explain *why* your answer works.\n",
"5. Treat the challenge section like exam prep or interview prep.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "1b5f35bd",
"source": [
"## Warm-up reflection\n",
"\n",
"Before coding, answer these questions in your own words:\n",
"- What is the main idea of this week's topic?\n",
"- What mistakes are beginners likely to make here?\n",
"- How might this topic appear in a real application or workplace task?\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "35ddfac0",
"execution_count": null,
"outputs": [],
"source": [
"# Warm-up starter for python basics\n",
"notes = []\n",
"print(\"Use this cell to write quick notes or small experiments about python basics.\")\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "386bb716",
"source": [
"## Exercise 1 — Read, predict, then run\n",
"\n",
"Read the code first. Predict the output on paper or in your head. Then run it and explain the result.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "41983a88",
"execution_count": null,
"outputs": [],
"source": [
"sample_values = [3, 7, 10]\n",
"for value in sample_values:\n",
" print(value * 2)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "fb57e097",
"source": [
"### Your task\n",
"\n",
"Change the values, run the cell again, and explain what changed.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "40e9e94b",
"source": [
"## Exercise 2 — Complete the starter code\n",
"\n",
"Finish the code so that it solves a small realistic problem.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "8787ba5c",
"execution_count": null,
"outputs": [],
"source": [
"project_name = \"Starter Project\"\n",
"completed_steps = 2\n",
"total_steps = 5\n",
"\n",
"# TODO: create a message that reports progress clearly.\n",
"# Example idea: \"Starter Project is 40% complete.\"\n",
"\n",
"message = \"Replace this text with your answer.\"\n",
"print(message)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "f64e5d4b",
"source": [
"## Exercise 3 — Debugging drill\n",
"\n",
"In real work, you often improve broken code instead of writing from scratch.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "207a9dfe",
"execution_count": null,
"outputs": [],
"source": [
"def broken_example(number):\n",
" # TODO: fix the logic so the function returns a useful value.\n",
" result = number + 1\n",
" return result\n",
"\n",
"print(broken_example(5))\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "cdf5eb36",
"source": [
"### Debugging questions\n",
"\n",
"- What is the code trying to do?\n",
"- Is the variable naming clear enough?\n",
"- How would you test your fix with more than one input?\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "baae46a7",
"source": [
"## Exercise 4 — Real-world mini scenario\n",
"\n",
"Imagine you are building a tiny internal tool at work. The code does not need to be huge; it needs to be clear, correct, and easy to maintain.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "accfee42",
"execution_count": null,
"outputs": [],
"source": [
"items_processed = 14\n",
"items_remaining = 6\n",
"\n",
"# TODO: write logic below that prints a helpful progress update for a teammate.\n",
"print(\"Add your progress update here.\")\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "c385d803",
"source": [
"## Exercise 5 — Explain your reasoning\n",
"\n",
"Write short answers in markdown or comments:\n",
"- Why is your solution readable?\n",
"- How could another developer understand it quickly?\n",
"- What edge case or mistake did you think about?\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "313e1570",
"source": [
"## Challenge set\n",
"\n",
"Try these without copying from earlier cells:\n",
"1. Solve a small version first.\n",
"2. Generalize your solution.\n",
"3. Test it with at least three different inputs.\n",
"4. Refactor any repeated logic.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "abfa785f",
"execution_count": null,
"outputs": [],
"source": [
"def challenge_task(data):\n",
" \"\"\"Replace this placeholder with your own solution for the challenge set.\"\"\"\n",
" return data\n",
"\n",
"print(challenge_task(\"start here\"))\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "f6d96e98",
"source": [
"## Topic-specific challenge ideas for Python Basics\n",
"\n",
"Use the problems below as exam prep, portfolio prep, or interview-style practice.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "3d53eb3d",
"source": [
"1. Build a profile card using variables and f-strings.\n",
"2. Convert text values into numbers and compute a total.\n",
"3. Compare two prices and report which is larger.\n",
"4. Create a mini receipt with formatted currency.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "18b9c999",
"source": [
"## Exam-prep mindset\n",
"\n",
"When preparing for major exams or technical interviews, do not just ask, “Can I memorize this?” Ask:\n",
"- Can I explain it clearly?\n",
"- Can I solve a fresh problem with it?\n",
"- Can I debug a broken version of it?\n",
"- Can I choose this approach for the right reason?\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "372f8b57",
"source": [
"## Career connection\n",
"\n",
"This week's practice is also training real workplace habits: clarity, testing, decomposition, communication, and disciplined thinking. Those habits matter in software engineering, data work, automation, QA, scripting, backend development, and many other roles.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "6364b70b",
"source": [
"## Self-check before moving on\n",
"\n",
"Rate yourself from 1 to 5 on each question:\n",
"- I can solve a straightforward problem from this topic without copying.\n",
"- I can explain the core idea to another learner.\n",
"- I can debug a small mistake in code from this topic.\n",
"- I can imagine a real-world use case for this topic.\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
================================================
FILE: week_1/0001_python_basics.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"id": "6dbed666",
"source": [
"# Python Basics — Week 1\n",
"\n",
"Welcome to the real beginning of the course. This notebook is intentionally longer and fuller than the later lessons because it lays the foundation for everything that follows.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "b7e88b47",
"source": [
"## Mission for this notebook\n",
"\n",
"Before moving to the next week, you should be able to:\n",
"- read and write simple Python statements\n",
"- use comments properly\n",
"- create, update, and inspect variables\n",
"- work with strings, integers, floats, and booleans\n",
"- use arithmetic, comparison, and logical operators\n",
"- convert values from one type to another\n",
"- understand the idea of user input\n",
"- combine multiple beginner ideas into small procedural programs\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "ec46c744",
"source": [
"## How to study this notebook well\n",
"\n",
"This is not a notebook to rush through. Run each code cell. Read the output. Change values. Re-run the cell. Then explain to yourself what changed and why.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "c03b3f82",
"source": [
"## 1. Your first Python output\n",
"\n",
"The `print()` function sends text or values to the screen.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "82790f5d",
"execution_count": null,
"outputs": [],
"source": [
"print(\"Hello, Python learner!\")\n",
"print(\"This is the beginning of your Python journey.\")\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "3f508f85",
"source": [
"## 2. Comments\n",
"\n",
"Comments help humans understand code. Python ignores comments when it runs the program.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "210a4ce9",
"execution_count": null,
"outputs": [],
"source": [
"# This line prints a message.\n",
"print(\"Comments are for people, not for Python.\")\n",
"\n",
"# Try uncommenting the next line.\n",
"# print(\"I am practicing by editing code.\")\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "3351e203",
"source": [
"## 3. Variables\n",
"\n",
"A variable is a name that stores a value so you can use that value again later.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "c1a8e880",
"execution_count": null,
"outputs": [],
"source": [
"student_name = \"Avery\"\n",
"study_hours = 2\n",
"confidence_score = 8.5\n",
"is_ready_to_practice = True\n",
"\n",
"print(student_name)\n",
"print(study_hours)\n",
"print(confidence_score)\n",
"print(is_ready_to_practice)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "ce72be70",
"source": [
"## 4. Data types\n",
"\n",
"Four beginner-friendly types appear all the time:\n",
"- `str` for text\n",
"- `int` for whole numbers\n",
"- `float` for decimals\n",
"- `bool` for `True` and `False`\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "26160e90",
"execution_count": null,
"outputs": [],
"source": [
"print(type(student_name))\n",
"print(type(study_hours))\n",
"print(type(confidence_score))\n",
"print(type(is_ready_to_practice))\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "94a68b2a",
"source": [
"## 5. Whole numbers and decimal numbers\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "af7d96d0",
"execution_count": null,
"outputs": [],
"source": [
"whole_number = 12\n",
"decimal_number = 12.75\n",
"negative_number = -4\n",
"\n",
"print(whole_number)\n",
"print(decimal_number)\n",
"print(negative_number)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "940ee976",
"source": [
"## 6. Strings\n",
"\n",
"Strings store text such as names, labels, messages, and sentences.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "de342881",
"execution_count": null,
"outputs": [],
"source": [
"course_title = \"Python Foundations\"\n",
"lesson_message = \"Readable code is a professional habit.\"\n",
"quote_message = \"Learning slowly is still learning well.\"\n",
"\n",
"print(course_title)\n",
"print(lesson_message)\n",
"print(quote_message)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "77e0d9fd",
"source": [
"## 7. Arithmetic operators\n",
"\n",
"Python supports addition, subtraction, multiplication, division, floor division, modulus, and exponentiation.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "1f3d0b74",
"execution_count": null,
"outputs": [],
"source": [
"a = 15\n",
"b = 4\n",
"\n",
"print(\"Addition:\", a + b)\n",
"print(\"Subtraction:\", a - b)\n",
"print(\"Multiplication:\", a * b)\n",
"print(\"Division:\", a / b)\n",
"print(\"Floor division:\", a // b)\n",
"print(\"Remainder:\", a % b)\n",
"print(\"Exponent:\", a ** 2)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "be382632",
"source": [
"## 8. Arithmetic in a realistic mini-scenario\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "20670e31",
"execution_count": null,
"outputs": [],
"source": [
"weekly_goal = 20\n",
"completed_lessons = 7\n",
"remaining_lessons = weekly_goal - completed_lessons\n",
"practice_sets = 3 * 4\n",
"average_score = 17 / 4\n",
"whole_groups = 17 // 4\n",
"leftover_items = 17 % 4\n",
"power_result = 2 ** 5\n",
"\n",
"print(\"Remaining lessons:\", remaining_lessons)\n",
"print(\"Practice sets:\", practice_sets)\n",
"print(\"Average score:\", average_score)\n",
"print(\"Whole groups:\", whole_groups)\n",
"print(\"Leftover items:\", leftover_items)\n",
"print(\"2 to the power of 5:\", power_result)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "1615e5fb",
"source": [
"## 9. Updating variables\n",
"\n",
"Variables can change as a program runs.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "97fbc03c",
"execution_count": null,
"outputs": [],
"source": [
"completed_lessons = completed_lessons + 3\n",
"study_hours += 1\n",
"confidence_score = confidence_score + 0.5\n",
"\n",
"print(\"Updated completed lessons:\", completed_lessons)\n",
"print(\"Updated study hours:\", study_hours)\n",
"print(\"Updated confidence score:\", confidence_score)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "0a9df4f0",
"source": [
"## 10. Assignment step by step\n",
"\n",
"Many beginners become stronger when they see values change line by line.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "4530253c",
"execution_count": null,
"outputs": [],
"source": [
"score = 10\n",
"print(\"Initial score:\", score)\n",
"\n",
"score = score + 5\n",
"print(\"After bonus:\", score)\n",
"\n",
"score = score * 2\n",
"print(\"After doubling:\", score)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "33815e44",
"source": [
"## 11. Casting and type conversion\n",
"\n",
"Casting means converting one type into another type.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "93ca9a97",
"execution_count": null,
"outputs": [],
"source": [
"whole_number_text = \"25\"\n",
"decimal_text = \"7.5\"\n",
"real_number = 19\n",
"\n",
"as_integer = int(whole_number_text)\n",
"as_float = float(decimal_text)\n",
"as_string = str(real_number)\n",
"\n",
"print(as_integer, type(as_integer))\n",
"print(as_float, type(as_float))\n",
"print(as_string, type(as_string))\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "66ee7b58",
"source": [
"## 12. Boolean conversions\n",
"\n",
"Python can also convert some values to `bool`.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "b979f023",
"execution_count": null,
"outputs": [],
"source": [
"print(bool(1))\n",
"print(bool(0))\n",
"print(bool(\"Python\"))\n",
"print(bool(\"\"))\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "cecf86c5",
"source": [
"## 13. Strings and concatenation\n",
"\n",
"We can join strings together using `+`, but everything must be a string.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "aa4ccd5a",
"execution_count": null,
"outputs": [],
"source": [
"first_name = \"Avery\"\n",
"last_name = \"Stone\"\n",
"full_name = first_name + \" \" + last_name\n",
"\n",
"print(full_name)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "9ef6cacb",
"source": [
"## 14. Mixing text and numbers\n",
"\n",
"If you want to join a number to text using `+`, cast the number first.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "27c43bbd",
"execution_count": null,
"outputs": [],
"source": [
"age = 14\n",
"print(\"Age:\", age)\n",
"print(\"I am \" + str(age) + \" years old.\")\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "eb770918",
"source": [
"## 15. f-strings\n",
"\n",
"F-strings are one of the best beginner tools in modern Python.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "93c323cb",
"execution_count": null,
"outputs": [],
"source": [
"summary = f\"{student_name} studied for {study_hours} hours and completed {completed_lessons} lessons.\"\n",
"print(summary)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "a9ae404e",
"source": [
"## 16. Other string formatting styles\n",
"\n",
"You may still see older formatting approaches in real code, so it helps to recognize them.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "717ff4fe",
"execution_count": null,
"outputs": [],
"source": [
"job = \"Engineer\"\n",
"name = \"Morgan\"\n",
"age = 28\n",
"\n",
"print(\"Hello, {}!\".format(name))\n",
"print(\"{} is a {}.\".format(name, job))\n",
"print(\"%s is %d years old.\" % (name, age))\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "bf1b9dd9",
"source": [
"## 17. Quotation marks in strings\n",
"\n",
"Python supports both single quotes and double quotes.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "bab88c61",
"execution_count": null,
"outputs": [],
"source": [
"message_one = \"Python is fun\"\n",
"message_two = 'You can also use single quotes'\n",
"message_three = \"It's okay to include an apostrophe like this.\"\n",
"\n",
"print(message_one)\n",
"print(message_two)\n",
"print(message_three)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "cf9a05b2",
"source": [
"## 18. Repeating strings\n",
"\n",
"The `*` operator can repeat a string.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "862a322f",
"execution_count": null,
"outputs": [],
"source": [
"print(\"-\" * 20)\n",
"print(\"Practice! \" * 3)\n",
"print(\"=\" * 20)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "bf16a03a",
"source": [
"## 19. String indexing\n",
"\n",
"Strings are ordered, so you can access characters by position.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "f1220468",
"execution_count": null,
"outputs": [],
"source": [
"language = \"Python\"\n",
"print(language[0])\n",
"print(language[1])\n",
"print(language[-1])\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "565a77c9",
"source": [
"## 20. String slicing\n",
"\n",
"Slicing lets you take part of a string.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "2d68e1a6",
"execution_count": null,
"outputs": [],
"source": [
"word = \"developer\"\n",
"print(word[:4])\n",
"print(word[4:])\n",
"print(word[1:6])\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "eec46f67",
"source": [
"## 21. Useful string methods\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "f73a2ced",
"execution_count": null,
"outputs": [],
"source": [
"topic = \"python basics\"\n",
"print(topic.upper())\n",
"print(topic.title())\n",
"print(topic.replace(\"basics\", \"journey\"))\n",
"print(len(topic))\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "40f2c454",
"source": [
"## 22. Comparison operators\n",
"\n",
"Comparison operators answer true-or-false questions.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "142c5b52",
"execution_count": null,
"outputs": [],
"source": [
"x = 5\n",
"y = 7\n",
"\n",
"print(x == y)\n",
"print(x != y)\n",
"print(x > y)\n",
"print(x < y)\n",
"print(x >= y)\n",
"print(x <= y)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "d78c6b03",
"source": [
"## 23. Comparing real values in context\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "4c033133",
"execution_count": null,
"outputs": [],
"source": [
"apple_price = 20\n",
"orange_price = 20\n",
"iphone_cost = 60000\n",
"android_cost = 35000\n",
"\n",
"print(apple_price == orange_price)\n",
"print(iphone_cost > android_cost)\n",
"print(iphone_cost < android_cost)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "1bf39600",
"source": [
"## 24. Logical operators\n",
"\n",
"Logical operators combine Boolean values.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "47413e84",
"execution_count": null,
"outputs": [],
"source": [
"p = True\n",
"v = False\n",
"\n",
"print(p and v)\n",
"print(p or v)\n",
"print(not p)\n",
"print(True and True and False)\n",
"print(False or False or True)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "3f70f9bf",
"source": [
"## 25. Booleans in practical conditions\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "1b33307a",
"execution_count": null,
"outputs": [],
"source": [
"finished_homework = True\n",
"attended_class = True\n",
"\n",
"ready_for_quiz = finished_homework and attended_class\n",
"print(ready_for_quiz)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "734e6a6b",
"source": [
"## 26. Simulating user input safely\n",
"\n",
"Interactive `input()` examples are important, but notebooks can become awkward if they always pause for typing. So we will simulate the result of user input with strings.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "99ed11b4",
"execution_count": null,
"outputs": [],
"source": [
"first_input = \"12\"\n",
"second_input = \"8\"\n",
"\n",
"print(type(first_input))\n",
"print(type(second_input))\n",
"print(first_input + second_input) # string concatenation, not number addition\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "0df35c70",
"source": [
"## 27. Turning simulated input into numbers\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "92cc86f6",
"execution_count": null,
"outputs": [],
"source": [
"first_number = int(first_input)\n",
"second_number = int(second_input)\n",
"answer = first_number + second_number\n",
"\n",
"print(type(first_number))\n",
"print(type(second_number))\n",
"print(answer)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "1897d4ab",
"source": [
"## 28. Floating-point formatting\n",
"\n",
"You can control how many decimal places appear in output.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "c2c523e5",
"execution_count": null,
"outputs": [],
"source": [
"num1 = 7\n",
"num2 = 3\n",
"result = num1 / num2\n",
"\n",
"print(result)\n",
"print(f\"Formatted to 2 decimal places: {result:.2f}\")\n",
"print(f\"Formatted to 4 decimal places: {result:.4f}\")\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "864cd1fe",
"source": [
"## 29. Bringing strings, numbers, and formatting together\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "4abc1af9",
"execution_count": null,
"outputs": [],
"source": [
"price_per_book = 14.99\n",
"number_of_books = 3\n",
"total_cost = price_per_book * number_of_books\n",
"\n",
"receipt = f\"Buying {number_of_books} books costs ${total_cost:.2f}.\"\n",
"print(receipt)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "d9797d3d",
"source": [
"## 30. Procedural mini-program: student profile\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "938ecb7f",
"execution_count": null,
"outputs": [],
"source": [
"name = \"Avery\"\n",
"age = 14\n",
"city = \"Maple Town\"\n",
"favorite_topic = \"Python basics\"\n",
"\n",
"print(f\"Hello! My name is {name}.\")\n",
"print(f\"I am {age} years old.\")\n",
"print(f\"I live in {city}.\")\n",
"print(f\"Right now I am studying {favorite_topic}.\")\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "9ff4f798",
"source": [
"## 31. Procedural mini-program: study planner\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "0c366563",
"execution_count": null,
"outputs": [],
"source": [
"subject = \"Python\"\n",
"minutes_per_session = 30\n",
"sessions_per_week = 5\n",
"weekly_minutes = minutes_per_session * sessions_per_week\n",
"\n",
"print(f\"Subject: {subject}\")\n",
"print(f\"Minutes per session: {minutes_per_session}\")\n",
"print(f\"Sessions per week: {sessions_per_week}\")\n",
"print(f\"Total weekly minutes: {weekly_minutes}\")\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "a244f9b9",
"source": [
"## 32. Procedural mini-program: shopping math\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "584f8dd5",
"execution_count": null,
"outputs": [],
"source": [
"notebook_price = 3.50\n",
"pencil_price = 1.25\n",
"eraser_price = 0.75\n",
"\n",
"total = notebook_price + pencil_price + eraser_price\n",
"print(f\"Total school supply cost: ${total:.2f}\")\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "a751a2fa",
"source": [
"## 33. Procedural mini-problem: animal legs\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "6c45d618",
"execution_count": null,
"outputs": [],
"source": [
"chickens = 20\n",
"rabbits = 15\n",
"total_legs = chickens * 2 + rabbits * 4\n",
"\n",
"print(\"Total legs on the farm:\", total_legs)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "60ac8d7a",
"source": [
"## 34. Procedural mini-problem: game coins\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "489296fc",
"execution_count": null,
"outputs": [],
"source": [
"coins = 10\n",
"earnings_per_win = 3\n",
"target = 20\n",
"games_needed = (target - coins) / earnings_per_win\n",
"\n",
"print(\"Games needed to reach the target:\", games_needed)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "4a5dd8be",
"source": [
"## 35. Procedural mini-problem: garden area\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "a690bfde",
"execution_count": null,
"outputs": [],
"source": [
"garden_width = 4\n",
"garden_length = 7\n",
"garden_area = garden_width * garden_length\n",
"\n",
"print(f\"Garden area: {garden_area} square meters\")\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "55f7b412",
"source": [
"## 36. What you should now recognize quickly\n",
"\n",
"At this point, these should feel familiar:\n",
"- `print()`\n",
"- variables\n",
"- strings, integers, floats, booleans\n",
"- arithmetic operators\n",
"- comparison operators\n",
"- logical operators\n",
"- casting with `int()`, `float()`, `str()`, `bool()`\n",
"- string formatting with commas, `+`, `.format()`, and f-strings\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "e9aa4f70",
"source": [
"## 37. Practice prompts\n",
"\n",
"1. Create three variables about yourself and print them.\n",
"2. Convert a numeric string like `\"42\"` into an integer.\n",
"3. Compare two numbers using at least three comparison operators.\n",
"4. Write an f-string that reports a total price.\n",
"5. Simulate user input with strings, cast them, and add them.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "dfd1cbd5",
"source": [
"## 38. Mastery checklist before Week 2\n",
"\n",
"You are ready to move on when you can confidently:\n",
"- explain what a variable is\n",
"- identify the type of a value\n",
"- predict the output of a short arithmetic expression\n",
"- convert values between basic types\n",
"- build readable output with f-strings\n",
"- understand the difference between text addition and numeric addition\n",
"- read and write a small procedural Python script on your own\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
================================================
FILE: week_2/0002_collections.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Data Structures and Collections — Week 2\n",
"\n",
"This notebook introduces the containers that help Python programs organize related pieces of data.\n"
],
"id": "a636e100"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Learning goals\n",
"\n",
"You will learn to:\n",
"- create and read lists, tuples, sets, and dictionaries\n",
"- choose a collection type based on the job\n",
"- reuse string formatting, variables, loops, and indexing from earlier lessons\n"
],
"id": "67741b76"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Why collections matter\n",
"\n",
"Real programs almost always work with groups of values. A class roster, a shopping cart, and a list of scores are all examples of grouped data.\n"
],
"id": "c9fca156"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Lists: ordered and changeable\n"
],
"id": "a45225d6"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"favorite_topics = [\"variables\", \"strings\", \"lists\"]\n",
"print(favorite_topics)\n",
"print(type(favorite_topics))\n",
"print(\"Number of topics:\", len(favorite_topics))\n"
],
"id": "de3e1e0f"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"study_plan = [\"review notes\", \"solve 3 problems\", \"take a short break\", \"write reflections\"]\n",
"\n",
"print(\"First task:\", study_plan[0])\n",
"print(\"Last task:\", study_plan[-1])\n"
],
"id": "72a19dbe"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Updating a list\n",
"\n",
"Lists are mutable, so we can change them over time.\n"
],
"id": "241a8f9d"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"study_plan.append(\"practice with a partner\")\n",
"study_plan[1] = \"solve 5 problems\"\n",
"\n",
"print(study_plan)\n"
],
"id": "a039f5ad"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Slicing a list\n",
"\n",
"Slicing lets us inspect part of the collection without changing it.\n"
],
"id": "25f36acb"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"weekly_scores = [72, 78, 81, 85, 90, 88, 93]\n",
"print(\"First three scores:\", weekly_scores[:3])\n",
"print(\"Middle scores:\", weekly_scores[2:5])\n",
"print(\"Every other score:\", weekly_scores[::2])\n"
],
"id": "197b9b4f"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Reusing loops from Week 1 and Week 2\n",
"\n",
"Collections become much more useful when we iterate over them.\n"
],
"id": "4c558e8d"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"for task in study_plan:\n",
" print(f\"Planned task: {task}\")\n"
],
"id": "b45c3ed3"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Tuples: ordered and stable\n",
"\n",
"Use a tuple when values belong together and should stay fixed.\n"
],
"id": "a8586dc0"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"rgb_color = (32, 145, 210)\n",
"print(rgb_color)\n",
"print(type(rgb_color))\n",
"print(f\"Red channel: {rgb_color[0]}\")\n"
],
"id": "7227d2a9"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Sets: unique values only\n",
"\n",
"Sets remove duplicates automatically.\n"
],
"id": "02ea7bfc"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"skills_practiced = {\"loops\", \"functions\", \"loops\", \"strings\"}\n",
"print(skills_practiced)\n",
"print(\"Unique skills practiced:\", len(skills_practiced))\n"
],
"id": "453306f4"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Dictionaries: key–value pairs\n",
"\n",
"Dictionaries are one of the most important structures in Python.\n"
],
"id": "c3a6cab2"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"source": [
"student_profile = {\n",
" \"name\": \"Avery\",\n",
" \"level\": \"beginner\",\n",
" \"completed_lessons\": 6,\n",
" \"favorite_topic\": \"strings\",\n",
"}\n",
"\n",
"print(student_profile)\n",
"print(student_profile[\"name\"])\n",
"print(student_profile[\"completed_lessons\"])\n"
],
"id": "cc94c65c"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"student_profile[\"completed_lessons\"] += 1\n",
"student_profile[\"goal\"] = \"build a small portfolio project\"\n",
"\n",
"for key, value in student_profile.items():\n",
" print(f\"{key}: {value}\")\n"
],
"id": "c232d608"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Comparing collection choices\n",
"\n",
"Ask these questions:\n",
"- Do I need order?\n",
"- Do I need labels?\n",
"- Do values have to stay unique?\n",
"- Will the collection change later?\n"
],
"id": "87526993"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"shopping_list = [\"notebook\", \"pencil\", \"eraser\"]\n",
"item_prices = {\"notebook\": 3.5, \"pencil\": 1.0, \"eraser\": 0.75}\n",
"\n",
"for item in shopping_list:\n",
" print(f\"{item}: ${item_prices[item]:.2f}\")\n"
],
"id": "e56b6d07"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Mini review\n",
"\n",
"In later notebooks, lists and dictionaries will appear again inside loops, functions, classes, and tests.\n"
],
"id": "0eb0162d"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Practice prompts\n",
"\n",
"1. Create a list of three hobbies and print the second one.\n",
"2. Create a set with repeated values and observe what happens.\n",
"3. Create a dictionary called `project_idea` with at least three keys.\n"
],
"id": "dc5cc083"
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
================================================
FILE: week_2/0002_practice_collections.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"id": "91293845",
"source": [
"# Week 2 Practice — Collections\n",
"\n",
"This practice notebook is designed to strengthen student thinking, not just student memory. The goal is to turn the week's lesson into repeatable skill.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "e5527e81",
"source": [
"## Why this practice notebook matters\n",
"\n",
"In real jobs, developers are expected to do more than remember syntax. They must inspect data carefully, break problems into parts, explain their reasoning, and produce dependable solutions under pressure. These exercises are built to train those habits early.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "167903b7",
"source": [
"## Focus areas\n",
"\n",
"- lists, tuples, sets, and dictionaries\n",
"- choosing the right structure\n",
"- iterating through grouped data\n",
"- organizing information like real applications\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "04f74dfb",
"source": [
"## How to use this notebook\n",
"\n",
"1. Solve the warm-up tasks first.\n",
"2. Write your own answer before looking for patterns.\n",
"3. Test small pieces of code often.\n",
"4. Explain *why* your answer works.\n",
"5. Treat the challenge section like exam prep or interview prep.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "6d44d0c5",
"source": [
"## Warm-up reflection\n",
"\n",
"Before coding, answer these questions in your own words:\n",
"- What is the main idea of this week's topic?\n",
"- What mistakes are beginners likely to make here?\n",
"- How might this topic appear in a real application or workplace task?\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "28f80528",
"execution_count": null,
"outputs": [],
"source": [
"# Warm-up starter for collections\n",
"notes = []\n",
"print(\"Use this cell to write quick notes or small experiments about collections.\")\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "bae55390",
"source": [
"## Exercise 1 — Read, predict, then run\n",
"\n",
"Read the code first. Predict the output on paper or in your head. Then run it and explain the result.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "0ed19b87",
"execution_count": null,
"outputs": [],
"source": [
"sample_values = [3, 7, 10]\n",
"for value in sample_values:\n",
" print(value * 2)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "7c0ee9ec",
"source": [
"### Your task\n",
"\n",
"Change the values, run the cell again, and explain what changed.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "d7110cc5",
"source": [
"## Exercise 2 — Complete the starter code\n",
"\n",
"Finish the code so that it solves a small realistic problem.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "c239d0ab",
"execution_count": null,
"outputs": [],
"source": [
"project_name = \"Starter Project\"\n",
"completed_steps = 2\n",
"total_steps = 5\n",
"\n",
"# TODO: create a message that reports progress clearly.\n",
"# Example idea: \"Starter Project is 40% complete.\"\n",
"\n",
"message = \"Replace this text with your answer.\"\n",
"print(message)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "b485c98a",
"source": [
"## Exercise 3 — Debugging drill\n",
"\n",
"In real work, you often improve broken code instead of writing from scratch.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "d6171f3e",
"execution_count": null,
"outputs": [],
"source": [
"def broken_example(number):\n",
" # TODO: fix the logic so the function returns a useful value.\n",
" result = number + 1\n",
" return result\n",
"\n",
"print(broken_example(5))\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "960f0694",
"source": [
"### Debugging questions\n",
"\n",
"- What is the code trying to do?\n",
"- Is the variable naming clear enough?\n",
"- How would you test your fix with more than one input?\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "42e89c41",
"source": [
"## Exercise 4 — Real-world mini scenario\n",
"\n",
"Imagine you are building a tiny internal tool at work. The code does not need to be huge; it needs to be clear, correct, and easy to maintain.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "79298f94",
"execution_count": null,
"outputs": [],
"source": [
"items_processed = 14\n",
"items_remaining = 6\n",
"\n",
"# TODO: write logic below that prints a helpful progress update for a teammate.\n",
"print(\"Add your progress update here.\")\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "65155b12",
"source": [
"## Exercise 5 — Explain your reasoning\n",
"\n",
"Write short answers in markdown or comments:\n",
"- Why is your solution readable?\n",
"- How could another developer understand it quickly?\n",
"- What edge case or mistake did you think about?\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "a633057d",
"source": [
"## Challenge set\n",
"\n",
"Try these without copying from earlier cells:\n",
"1. Solve a small version first.\n",
"2. Generalize your solution.\n",
"3. Test it with at least three different inputs.\n",
"4. Refactor any repeated logic.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "1eb9581e",
"execution_count": null,
"outputs": [],
"source": [
"def challenge_task(data):\n",
" \"\"\"Replace this placeholder with your own solution for the challenge set.\"\"\"\n",
" return data\n",
"\n",
"print(challenge_task(\"start here\"))\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "4149a7ea",
"source": [
"## Topic-specific challenge ideas for Collections\n",
"\n",
"Use the problems below as exam prep, portfolio prep, or interview-style practice.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "dc344758",
"source": [
"1. Store student scores in a list and compute a summary.\n",
"2. Use a set to identify unique skills in a training program.\n",
"3. Create a dictionary for a user profile and print a readable report.\n",
"4. Decide which collection you would use for inventory, coordinates, and account data.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "07e6348a",
"source": [
"## Exam-prep mindset\n",
"\n",
"When preparing for major exams or technical interviews, do not just ask, “Can I memorize this?” Ask:\n",
"- Can I explain it clearly?\n",
"- Can I solve a fresh problem with it?\n",
"- Can I debug a broken version of it?\n",
"- Can I choose this approach for the right reason?\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "458f708e",
"source": [
"## Career connection\n",
"\n",
"This week's practice is also training real workplace habits: clarity, testing, decomposition, communication, and disciplined thinking. Those habits matter in software engineering, data work, automation, QA, scripting, backend development, and many other roles.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "8b052e2f",
"source": [
"## Self-check before moving on\n",
"\n",
"Rate yourself from 1 to 5 on each question:\n",
"- I can solve a straightforward problem from this topic without copying.\n",
"- I can explain the core idea to another learner.\n",
"- I can debug a small mistake in code from this topic.\n",
"- I can imagine a real-world use case for this topic.\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
================================================
FILE: week_3/0003_Loops.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Loops in Python\n",
"\n",
"Loops let us repeat useful work without copying the same code again and again.\n"
],
"id": "7c2fc316"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Learning goals\n",
"\n",
"You will practice:\n",
"- `for` loops over collections\n",
"- `range()` for repeated counting\n",
"- `while` loops for condition-based repetition\n",
"- combining loops with strings, lists, and conditions from earlier notebooks\n"
],
"id": "e5764712"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## A basic `for` loop\n"
],
"id": "2d308d15"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"students = [\"Avery\", \"Jordan\", \"Riley\", \"Sam\"]\n",
"\n",
"for student in students:\n",
" print(student)\n"
],
"id": "9c0c7577"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Using f-strings inside loops\n"
],
"id": "fdaa057f"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"for student in students:\n",
" print(f\"Welcome, {student}. Keep going.\")\n"
],
"id": "5094cd2a"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Counting with `range()`\n"
],
"id": "ff74ae4b"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"for attempt in range(1, 6):\n",
" print(f\"Practice attempt #{attempt}\")\n"
],
"id": "f390e8d2"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Looping through indexes\n"
],
"id": "8e36b895"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"scores = [78, 85, 91, 88]\n",
"\n",
"for index in range(len(scores)):\n",
" print(f\"Score {index}: {scores[index]}\")\n"
],
"id": "55a43a8e"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## A loop with conditions\n",
"\n",
"Earlier topics still matter here.\n"
],
"id": "ec5a01c9"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"for score in scores:\n",
" if score >= 90:\n",
" print(f\"{score} is an excellent result.\")\n",
" else:\n",
" print(f\"{score} shows progress.\")\n"
],
"id": "c30a0a3c"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Building a total with a loop\n"
],
"id": "b098da61"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"total_score = 0\n",
"for score in scores:\n",
" total_score += score\n",
"\n",
"print(\"Total score:\", total_score)\n",
"print(\"Average score:\", total_score / len(scores))\n"
],
"id": "e1a0857c"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## `while` loops\n",
"\n",
"Use a `while` loop when repetition depends on a changing condition.\n"
],
"id": "05687f0b"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"countdown = 3\n",
"\n",
"while countdown > 0:\n",
" print(countdown)\n",
" countdown -= 1\n",
"\n",
"print(\"Start!\")\n"
],
"id": "e569ce27"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Another `while` example\n"
],
"id": "a80b506f"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"energy = 5\n",
"\n",
"while energy > 0:\n",
" print(f\"Working... energy level: {energy}\")\n",
" energy -= 1\n"
],
"id": "44c98e7a"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Avoiding infinite loops\n",
"\n",
"Always make sure the loop condition can eventually become false.\n"
],
"id": "19046577"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"password_attempts = 0\n",
"while password_attempts < 3:\n",
" password_attempts += 1\n",
" print(f\"Attempt number {password_attempts}\")\n"
],
"id": "da52712c"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Practice prompts\n",
"\n",
"1. Print the squares of 1 through 5.\n",
"2. Loop through a list of words and print their lengths.\n",
"3. Use a `while` loop to count from 1 to 4.\n"
],
"id": "d3b4d1f5"
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
================================================
FILE: week_3/0003_ifelifelse.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Conditions in Python\n",
"\n",
"Programs become interesting when they can make decisions based on data.\n"
],
"id": "60d57c53"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Learning goals\n",
"\n",
"By the end of this notebook, you should be able to:\n",
"- compare values with condition operators\n",
"- use `if`, `elif`, and `else` blocks\n",
"- combine conditions with variables and strings from earlier lessons\n"
],
"id": "0aa94b08"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## A first condition\n"
],
"id": "1bb8b7b2"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"temperature = 24\n",
"\n",
"if temperature > 30:\n",
" print(\"It is a hot day.\")\n",
"else:\n",
" print(\"It is not a hot day.\")\n"
],
"id": "2957e014"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Equality and inequality\n"
],
"id": "16236e66"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"completed_exercises = 10\n",
"required_exercises = 10\n",
"\n",
"if completed_exercises == required_exercises:\n",
" print(\"You met the goal.\")\n",
"else:\n",
" print(\"You still have work to do.\")\n"
],
"id": "26399488"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"project_status = \"draft\"\n",
"\n",
"if project_status != \"published\":\n",
" print(\"The project is still in progress.\")\n"
],
"id": "bf16bf61"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Multiple branches with `elif`\n"
],
"id": "35acbe9a"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"quiz_score = 87\n",
"\n",
"if quiz_score >= 90:\n",
" print(\"Excellent work.\")\n",
"elif quiz_score >= 75:\n",
" print(\"Good progress. Keep practicing.\")\n",
"else:\n",
" print(\"Review the lesson and try again.\")\n"
],
"id": "f56b67a0"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Conditions with strings\n"
],
"id": "ac3f00dc"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"command = \"save\"\n",
"\n",
"if command == \"run\":\n",
" print(\"Running the script...\")\n",
"elif command == \"save\":\n",
" print(\"Saving your work...\")\n",
"else:\n",
" print(\"Unknown command.\")\n"
],
"id": "bb33938a"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Reusing earlier topics\n",
"\n",
"We can combine conditions with lists, lengths, and f-strings.\n"
],
"id": "d8926751"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"pending_tasks = [\"review loops\", \"practice functions\"]\n",
"\n",
"if len(pending_tasks) > 0:\n",
" print(f\"You still have {len(pending_tasks)} tasks to complete.\")\n",
"else:\n",
" print(\"You are done for the day.\")\n"
],
"id": "dd4e0b65"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Nested decision-making\n",
"\n",
"You do not always need nested conditions, but it is helpful to recognize them.\n"
],
"id": "5b3faabf"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"study_hours = 3\n",
"quiz_score = 92\n",
"\n",
"if study_hours >= 2:\n",
" if quiz_score >= 90:\n",
" print(\"Strong preparation and strong result.\")\n",
" else:\n",
" print(\"Good effort. Review a few weak spots.\")\n",
"else:\n",
" print(\"Try scheduling more practice time.\")\n"
],
"id": "6ec43b97"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Readability tip\n",
"\n",
"Try to keep each condition understandable at a glance. If the logic becomes too tangled, it may belong in a function later.\n"
],
"id": "bc6b317f"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Practice prompts\n",
"\n",
"1. Write a condition that checks whether a number is positive, zero, or negative.\n",
"2. Check whether a username is long enough.\n",
"3. Use a list and `len()` inside a condition.\n"
],
"id": "2f197fc7"
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
================================================
FILE: week_3/0003_practice_control_flow.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"id": "67984ca3",
"source": [
"# Week 3 Practice — Conditions and Loops\n",
"\n",
"This practice notebook is designed to strengthen student thinking, not just student memory. The goal is to turn the week's lesson into repeatable skill.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "787e7e4a",
"source": [
"## Why this practice notebook matters\n",
"\n",
"In real jobs, developers are expected to do more than remember syntax. They must inspect data carefully, break problems into parts, explain their reasoning, and produce dependable solutions under pressure. These exercises are built to train those habits early.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "63b0a20d",
"source": [
"## Focus areas\n",
"\n",
"- if/elif/else reasoning\n",
"- truthy and falsy thinking\n",
"- for loops and while loops\n",
"- building mental discipline for debugging\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "c00042a2",
"source": [
"## How to use this notebook\n",
"\n",
"1. Solve the warm-up tasks first.\n",
"2. Write your own answer before looking for patterns.\n",
"3. Test small pieces of code often.\n",
"4. Explain *why* your answer works.\n",
"5. Treat the challenge section like exam prep or interview prep.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "3323f55d",
"source": [
"## Warm-up reflection\n",
"\n",
"Before coding, answer these questions in your own words:\n",
"- What is the main idea of this week's topic?\n",
"- What mistakes are beginners likely to make here?\n",
"- How might this topic appear in a real application or workplace task?\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "35fcc83c",
"execution_count": null,
"outputs": [],
"source": [
"# Warm-up starter for control flow\n",
"notes = []\n",
"print(\"Use this cell to write quick notes or small experiments about control flow.\")\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "16d06e3c",
"source": [
"## Exercise 1 — Read, predict, then run\n",
"\n",
"Read the code first. Predict the output on paper or in your head. Then run it and explain the result.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "fff4142e",
"execution_count": null,
"outputs": [],
"source": [
"sample_values = [3, 7, 10]\n",
"for value in sample_values:\n",
" print(value * 2)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "2a4605d8",
"source": [
"### Your task\n",
"\n",
"Change the values, run the cell again, and explain what changed.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "7fbfa300",
"source": [
"## Exercise 2 — Complete the starter code\n",
"\n",
"Finish the code so that it solves a small realistic problem.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "7166e7e0",
"execution_count": null,
"outputs": [],
"source": [
"project_name = \"Starter Project\"\n",
"completed_steps = 2\n",
"total_steps = 5\n",
"\n",
"# TODO: create a message that reports progress clearly.\n",
"# Example idea: \"Starter Project is 40% complete.\"\n",
"\n",
"message = \"Replace this text with your answer.\"\n",
"print(message)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "ef66d987",
"source": [
"## Exercise 3 — Debugging drill\n",
"\n",
"In real work, you often improve broken code instead of writing from scratch.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "9f992a0b",
"execution_count": null,
"outputs": [],
"source": [
"def broken_example(number):\n",
" # TODO: fix the logic so the function returns a useful value.\n",
" result = number + 1\n",
" return result\n",
"\n",
"print(broken_example(5))\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "ed3cebc1",
"source": [
"### Debugging questions\n",
"\n",
"- What is the code trying to do?\n",
"- Is the variable naming clear enough?\n",
"- How would you test your fix with more than one input?\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "82a88938",
"source": [
"## Exercise 4 — Real-world mini scenario\n",
"\n",
"Imagine you are building a tiny internal tool at work. The code does not need to be huge; it needs to be clear, correct, and easy to maintain.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "aa3abb18",
"execution_count": null,
"outputs": [],
"source": [
"items_processed = 14\n",
"items_remaining = 6\n",
"\n",
"# TODO: write logic below that prints a helpful progress update for a teammate.\n",
"print(\"Add your progress update here.\")\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "bb588749",
"source": [
"## Exercise 5 — Explain your reasoning\n",
"\n",
"Write short answers in markdown or comments:\n",
"- Why is your solution readable?\n",
"- How could another developer understand it quickly?\n",
"- What edge case or mistake did you think about?\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "30c70090",
"source": [
"## Challenge set\n",
"\n",
"Try these without copying from earlier cells:\n",
"1. Solve a small version first.\n",
"2. Generalize your solution.\n",
"3. Test it with at least three different inputs.\n",
"4. Refactor any repeated logic.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "eec6704f",
"execution_count": null,
"outputs": [],
"source": [
"def challenge_task(data):\n",
" \"\"\"Replace this placeholder with your own solution for the challenge set.\"\"\"\n",
" return data\n",
"\n",
"print(challenge_task(\"start here\"))\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "5fdfa4f6",
"source": [
"## Topic-specific challenge ideas for Control Flow\n",
"\n",
"Use the problems below as exam prep, portfolio prep, or interview-style practice.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "ce09e177",
"source": [
"1. Grade a score using `if/elif/else`.\n",
"2. Detect whether a list is empty using truthiness.\n",
"3. Loop through tasks and print a status line for each one.\n",
"4. Use a `while` loop to simulate repeated attempts until a goal is reached.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "45656ca1",
"source": [
"## Exam-prep mindset\n",
"\n",
"When preparing for major exams or technical interviews, do not just ask, “Can I memorize this?” Ask:\n",
"- Can I explain it clearly?\n",
"- Can I solve a fresh problem with it?\n",
"- Can I debug a broken version of it?\n",
"- Can I choose this approach for the right reason?\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "17645365",
"source": [
"## Career connection\n",
"\n",
"This week's practice is also training real workplace habits: clarity, testing, decomposition, communication, and disciplined thinking. Those habits matter in software engineering, data work, automation, QA, scripting, backend development, and many other roles.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "b84fb489",
"source": [
"## Self-check before moving on\n",
"\n",
"Rate yourself from 1 to 5 on each question:\n",
"- I can solve a straightforward problem from this topic without copying.\n",
"- I can explain the core idea to another learner.\n",
"- I can debug a small mistake in code from this topic.\n",
"- I can imagine a real-world use case for this topic.\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
================================================
FILE: week_3/0003_truthyandfalsies.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Truthy and Falsy Values\n",
"\n",
"Python often lets us treat values as true or false without writing an explicit comparison.\n"
],
"id": "771ed152"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Learning goals\n",
"\n",
"You will learn to:\n",
"- recognize common truthy and falsy values\n",
"- use concise condition checks\n",
"- connect Boolean thinking to lists, strings, and dictionaries from earlier lessons\n"
],
"id": "ccf88283"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Common falsy values\n"
],
"id": "f6f56b0e"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"values_to_check = [0, 0.0, \"\", [], {}, None]\n",
"\n",
"for value in values_to_check:\n",
" if value:\n",
" print(value, \"is truthy\")\n",
" else:\n",
" print(repr(value), \"is falsy\")\n"
],
"id": "f2c07a31"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Common truthy values\n"
],
"id": "76bdd313"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"examples = [42, \"Python\", [1, 2, 3], {\"topic\": \"loops\"}]\n",
"\n",
"for value in examples:\n",
" if value:\n",
" print(repr(value), \"is truthy\")\n"
],
"id": "380d2798"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Why this matters\n",
"\n",
"Truthy and falsy checks make code shorter, especially with strings and collections.\n"
],
"id": "15acfbbe"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"pending_tasks = [\"read notes\", \"solve exercise 2\"]\n",
"\n",
"if pending_tasks:\n",
" print(\"You have tasks to finish.\")\n",
"else:\n",
" print(\"Your task list is empty.\")\n"
],
"id": "73426b95"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"user_input = \"\"\n",
"\n",
"if not user_input:\n",
" print(\"Please type something before continuing.\")\n"
],
"id": "e463ee47"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Dictionaries and truthiness\n"
],
"id": "4d2229a6"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"profile = {}\n",
"\n",
"if profile:\n",
" print(\"Profile is ready.\")\n",
"else:\n",
" print(\"Profile is still empty.\")\n"
],
"id": "98c95d91"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Combining with earlier topics\n",
"\n",
"Truthiness is useful inside loops and functions, not just one-time checks.\n"
],
"id": "f42abb6e"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"messages = [\"Welcome\", \"Keep going\", \"\"]\n",
"\n",
"for message in messages:\n",
" if message:\n",
" print(f\"Display message: {message}\")\n",
" else:\n",
" print(\"Skip the empty message.\")\n"
],
"id": "d502511f"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Readability reminder\n",
"\n",
"Truthy and falsy values are powerful, but do not let brevity hide your meaning.\n"
],
"id": "9543341f"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Practice prompts\n",
"\n",
"1. Create an empty list and check it in an `if` statement.\n",
"2. Create a non-empty string and test it.\n",
"3. Explain why `None` is useful in conditional logic.\n"
],
"id": "1fb37f94"
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
================================================
FILE: week_4/0004_Functions.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Functions — Week 4\n",
"\n",
"Functions help us organize code into reusable, meaningful pieces.\n"
],
"id": "f0c83c97"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Learning goals\n",
"\n",
"You will learn to:\n",
"- define and call functions\n",
"- work with parameters and return values\n",
"- use default arguments and `*args`\n",
"- combine functions with loops, conditions, and collections from earlier notebooks\n"
],
"id": "4d11cb9e"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## A simple function\n"
],
"id": "a346d8e2"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def add_numbers(first_number, second_number):\n",
" \"\"\"Return the sum of two numbers.\"\"\"\n",
" return first_number + second_number\n",
"\n",
"print(add_numbers(4, 3))\n"
],
"id": "7f603999"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Parameters and arguments\n"
],
"id": "1bda0d7e"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def describe_course(course_name, lesson_count):\n",
" return f\"{course_name} includes {lesson_count} lessons.\"\n",
"\n",
"print(describe_course(\"Python Foundations\", 8))\n"
],
"id": "3a06b8a7"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Returning values\n",
"\n",
"Returning data gives the caller more freedom than printing too early.\n"
],
"id": "e5368158"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def calculate_area(width, height):\n",
" return width * height\n",
"\n",
"room_area = calculate_area(5, 4)\n",
"print(f\"Area: {room_area}\")\n"
],
"id": "0dbe6c59"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Functions with conditions\n"
],
"id": "6e003019"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def check_passing_score(score):\n",
" if score >= 75:\n",
" return \"pass\"\n",
" return \"review\"\n",
"\n",
"print(check_passing_score(82))\n",
"print(check_passing_score(60))\n"
],
"id": "0e12e085"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Default arguments\n"
],
"id": "8ba72f84"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def greet_student(name, greeting=\"Welcome\"):\n",
" return f\"{greeting}, {name}!\"\n",
"\n",
"print(greet_student(\"Avery\"))\n",
"print(greet_student(\"Jordan\", greeting=\"Great to see you\"))\n"
],
"id": "a4295a07"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Variable-length arguments with `*args`\n"
],
"id": "afebe084"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def total_points(*scores):\n",
" return sum(scores)\n",
"\n",
"print(total_points(5, 10, 15))\n",
"print(total_points(7, 7, 7, 7))\n"
],
"id": "3fdca638"
},
{
"cell_type": "markdown",
"metadata": {},
"outputs": [],
"source": [
"## Functions with loops\n"
],
"id": "a688a5c4"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def print_tasks(tasks):\n",
" for task in tasks:\n",
" print(f\"Task: {task}\")\n",
"\n",
"print_tasks([\"read notes\", \"solve exercise\", \"rest\"])\n"
],
"id": "dd84e85f"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## A realistic example\n"
],
"id": "0e76cb7b"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def apply_discount(price, percent_discount):\n",
" discount_amount = price * (percent_discount / 100)\n",
" return price - discount_amount\n",
"\n",
"final_price = apply_discount(120, 15)\n",
"print(f\"Discounted price: ${final_price:.2f}\")\n"
],
"id": "b82d9df5"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Functions returning collections\n"
],
"id": "bb77defc"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def build_progress_report(name, completed_lessons):\n",
" return {\n",
" \"name\": name,\n",
" \"completed_lessons\": completed_lessons,\n",
" \"status\": \"on track\" if completed_lessons >= 5 else \"keep practicing\",\n",
" }\n",
"\n",
"report = build_progress_report(\"Avery\", 6)\n",
"print(report)\n"
],
"id": "0f9f1575"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Professional note\n",
"\n",
"If a task has a name, repeated logic, or a useful output, it probably deserves a function.\n"
],
"id": "1be316c3"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Practice prompts\n",
"\n",
"1. Write a function that converts minutes to seconds.\n",
"2. Write a function that checks whether a list is empty.\n",
"3. Write a function that prints each item in a dictionary.\n"
],
"id": "f89f70f7"
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
================================================
FILE: week_4/0004_practice_functions.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"id": "b8b88d24",
"source": [
"# Week 4 Practice — Functions\n",
"\n",
"This practice notebook is designed to strengthen student thinking, not just student memory. The goal is to turn the week's lesson into repeatable skill.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "51608224",
"source": [
"## Why this practice notebook matters\n",
"\n",
"In real jobs, developers are expected to do more than remember syntax. They must inspect data carefully, break problems into parts, explain their reasoning, and produce dependable solutions under pressure. These exercises are built to train those habits early.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "0f45dc86",
"source": [
"## Focus areas\n",
"\n",
"- parameters and return values\n",
"- breaking problems into reusable pieces\n",
"- testing tiny parts of a solution\n",
"- thinking like a real developer\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "bb258528",
"source": [
"## How to use this notebook\n",
"\n",
"1. Solve the warm-up tasks first.\n",
"2. Write your own answer before looking for patterns.\n",
"3. Test small pieces of code often.\n",
"4. Explain *why* your answer works.\n",
"5. Treat the challenge section like exam prep or interview prep.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "095f27cc",
"source": [
"## Warm-up reflection\n",
"\n",
"Before coding, answer these questions in your own words:\n",
"- What is the main idea of this week's topic?\n",
"- What mistakes are beginners likely to make here?\n",
"- How might this topic appear in a real application or workplace task?\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "ff4c60f6",
"execution_count": null,
"outputs": [],
"source": [
"# Warm-up starter for functions\n",
"notes = []\n",
"print(\"Use this cell to write quick notes or small experiments about functions.\")\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "12acf59c",
"source": [
"## Exercise 1 — Read, predict, then run\n",
"\n",
"Read the code first. Predict the output on paper or in your head. Then run it and explain the result.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "0a176e45",
"execution_count": null,
"outputs": [],
"source": [
"sample_values = [3, 7, 10]\n",
"for value in sample_values:\n",
" print(value * 2)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "cc20ee57",
"source": [
"### Your task\n",
"\n",
"Change the values, run the cell again, and explain what changed.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "fe05c46b",
"source": [
"## Exercise 2 — Complete the starter code\n",
"\n",
"Finish the code so that it solves a small realistic problem.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "6d0c939a",
"execution_count": null,
"outputs": [],
"source": [
"project_name = \"Starter Project\"\n",
"completed_steps = 2\n",
"total_steps = 5\n",
"\n",
"# TODO: create a message that reports progress clearly.\n",
"# Example idea: \"Starter Project is 40% complete.\"\n",
"\n",
"message = \"Replace this text with your answer.\"\n",
"print(message)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "7687a3eb",
"source": [
"## Exercise 3 — Debugging drill\n",
"\n",
"In real work, you often improve broken code instead of writing from scratch.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "b23850fc",
"execution_count": null,
"outputs": [],
"source": [
"def broken_example(number):\n",
" # TODO: fix the logic so the function returns a useful value.\n",
" result = number + 1\n",
" return result\n",
"\n",
"print(broken_example(5))\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "4beb665e",
"source": [
"### Debugging questions\n",
"\n",
"- What is the code trying to do?\n",
"- Is the variable naming clear enough?\n",
"- How would you test your fix with more than one input?\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "3c9e6159",
"source": [
"## Exercise 4 — Real-world mini scenario\n",
"\n",
"Imagine you are building a tiny internal tool at work. The code does not need to be huge; it needs to be clear, correct, and easy to maintain.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "4fd4d11c",
"execution_count": null,
"outputs": [],
"source": [
"items_processed = 14\n",
"items_remaining = 6\n",
"\n",
"# TODO: write logic below that prints a helpful progress update for a teammate.\n",
"print(\"Add your progress update here.\")\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "e4d1457e",
"source": [
"## Exercise 5 — Explain your reasoning\n",
"\n",
"Write short answers in markdown or comments:\n",
"- Why is your solution readable?\n",
"- How could another developer understand it quickly?\n",
"- What edge case or mistake did you think about?\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "f010b053",
"source": [
"## Challenge set\n",
"\n",
"Try these without copying from earlier cells:\n",
"1. Solve a small version first.\n",
"2. Generalize your solution.\n",
"3. Test it with at least three different inputs.\n",
"4. Refactor any repeated logic.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "4076df06",
"execution_count": null,
"outputs": [],
"source": [
"def challenge_task(data):\n",
" \"\"\"Replace this placeholder with your own solution for the challenge set.\"\"\"\n",
" return data\n",
"\n",
"print(challenge_task(\"start here\"))\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "4929ef06",
"source": [
"## Topic-specific challenge ideas for Functions\n",
"\n",
"Use the problems below as exam prep, portfolio prep, or interview-style practice.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "208cb2b4",
"source": [
"1. Write a function that formats a learner report.\n",
"2. Write a function that returns the average of a list of numbers.\n",
"3. Refactor repeated code into a helper function.\n",
"4. Think about which functions should return values instead of printing them.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "81a84268",
"source": [
"## Exam-prep mindset\n",
"\n",
"When preparing for major exams or technical interviews, do not just ask, “Can I memorize this?” Ask:\n",
"- Can I explain it clearly?\n",
"- Can I solve a fresh problem with it?\n",
"- Can I debug a broken version of it?\n",
"- Can I choose this approach for the right reason?\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "db3a0589",
"source": [
"## Career connection\n",
"\n",
"This week's practice is also training real workplace habits: clarity, testing, decomposition, communication, and disciplined thinking. Those habits matter in software engineering, data work, automation, QA, scripting, backend development, and many other roles.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "5ece7712",
"source": [
"## Self-check before moving on\n",
"\n",
"Rate yourself from 1 to 5 on each question:\n",
"- I can solve a straightforward problem from this topic without copying.\n",
"- I can explain the core idea to another learner.\n",
"- I can debug a small mistake in code from this topic.\n",
"- I can imagine a real-world use case for this topic.\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
================================================
FILE: week_5/0005 recursion.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Recursion\n",
"\n",
"Recursion happens when a function solves a problem by calling itself on a smaller version of the same problem.\n"
],
"id": "d9b7a6aa"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Learning goals\n",
"\n",
"You will learn to:\n",
"- identify a base case and a recursive step\n",
"- trace recursive calls carefully\n",
"- compare recursion with loops and collections from earlier notebooks\n"
],
"id": "5cb89dd6"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## The two required parts\n",
"\n",
"Every recursive function needs:\n",
"1. a **base case** that stops the recursion\n",
"2. a **recursive step** that moves toward the base case\n"
],
"id": "fc2f4c41"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def factorial(number):\n",
" if number == 0:\n",
" return 1\n",
" return number * factorial(number - 1)\n",
"\n",
"print(factorial(5))\n"
],
"id": "28889d2a"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Tracing the flow\n",
"\n",
"`factorial(5)` becomes `5 * factorial(4)`, then `4 * factorial(3)`, and continues until it reaches `factorial(0)`.\n"
],
"id": "e5a0d1a0"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def countdown(number):\n",
" if number == 0:\n",
" print(\"Lift off!\")\n",
" return\n",
" print(number)\n",
" countdown(number - 1)\n",
"\n",
"countdown(5)\n"
],
"id": "b1ef16e1"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Recursion with nested collections\n",
"\n",
"This example revisits lists from earlier notebooks.\n"
],
"id": "da6721b0"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def sum_nested_numbers(data):\n",
" if isinstance(data, list):\n",
" total = 0\n",
" for item in data:\n",
" total += sum_nested_numbers(item)\n",
" return total\n",
" return data\n",
"\n",
"numbers = [1, [2, 3], [4, [5, 6]]]\n",
"print(sum_nested_numbers(numbers))\n"
],
"id": "83f3e878"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Another recursive example\n"
],
"id": "26196dd8"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def sum_to_n(number):\n",
" if number == 1:\n",
" return 1\n",
" return number + sum_to_n(number - 1)\n",
"\n",
"print(sum_to_n(5))\n"
],
"id": "1c608bda"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## When recursion is a good fit\n",
"\n",
"Recursion is useful for nested structures, tree-like data, and problems that shrink naturally.\n"
],
"id": "2697ea9b"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Practice prompts\n",
"\n",
"1. Modify `countdown()` to print a custom message at the end.\n",
"2. Try writing a recursive function that counts the number of items in a nested list.\n",
"3. Compare one recursive example to a loop-based version.\n"
],
"id": "43390cd3"
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
================================================
FILE: week_5/0005_practice_recursion.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"id": "1ed47e37",
"source": [
"# Week 5 Practice — Recursion\n",
"\n",
"This practice notebook is designed to strengthen student thinking, not just student memory. The goal is to turn the week's lesson into repeatable skill.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "c786bbc2",
"source": [
"## Why this practice notebook matters\n",
"\n",
"In real jobs, developers are expected to do more than remember syntax. They must inspect data carefully, break problems into parts, explain their reasoning, and produce dependable solutions under pressure. These exercises are built to train those habits early.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "984079cf",
"source": [
"## Focus areas\n",
"\n",
"- base case and recursive step\n",
"- tracing recursive calls\n",
"- comparing recursion with loops\n",
"- solving nested-data problems\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "8df7f0e1",
"source": [
"## How to use this notebook\n",
"\n",
"1. Solve the warm-up tasks first.\n",
"2. Write your own answer before looking for patterns.\n",
"3. Test small pieces of code often.\n",
"4. Explain *why* your answer works.\n",
"5. Treat the challenge section like exam prep or interview prep.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "9dc374f5",
"source": [
"## Warm-up reflection\n",
"\n",
"Before coding, answer these questions in your own words:\n",
"- What is the main idea of this week's topic?\n",
"- What mistakes are beginners likely to make here?\n",
"- How might this topic appear in a real application or workplace task?\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "53ed065e",
"execution_count": null,
"outputs": [],
"source": [
"# Warm-up starter for recursion\n",
"notes = []\n",
"print(\"Use this cell to write quick notes or small experiments about recursion.\")\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "851efab0",
"source": [
"## Exercise 1 — Read, predict, then run\n",
"\n",
"Read the code first. Predict the output on paper or in your head. Then run it and explain the result.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "5f6569f4",
"execution_count": null,
"outputs": [],
"source": [
"sample_values = [3, 7, 10]\n",
"for value in sample_values:\n",
" print(value * 2)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "f8749a1d",
"source": [
"### Your task\n",
"\n",
"Change the values, run the cell again, and explain what changed.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "6c943cfc",
"source": [
"## Exercise 2 — Complete the starter code\n",
"\n",
"Finish the code so that it solves a small realistic problem.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "f7773be5",
"execution_count": null,
"outputs": [],
"source": [
"project_name = \"Starter Project\"\n",
"completed_steps = 2\n",
"total_steps = 5\n",
"\n",
"# TODO: create a message that reports progress clearly.\n",
"# Example idea: \"Starter Project is 40% complete.\"\n",
"\n",
"message = \"Replace this text with your answer.\"\n",
"print(message)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "1ec1fcc7",
"source": [
"## Exercise 3 — Debugging drill\n",
"\n",
"In real work, you often improve broken code instead of writing from scratch.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "6588da0d",
"execution_count": null,
"outputs": [],
"source": [
"def broken_example(number):\n",
" # TODO: fix the logic so the function returns a useful value.\n",
" result = number + 1\n",
" return result\n",
"\n",
"print(broken_example(5))\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "50e582a0",
"source": [
"### Debugging questions\n",
"\n",
"- What is the code trying to do?\n",
"- Is the variable naming clear enough?\n",
"- How would you test your fix with more than one input?\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "bf87dbf8",
"source": [
"## Exercise 4 — Real-world mini scenario\n",
"\n",
"Imagine you are building a tiny internal tool at work. The code does not need to be huge; it needs to be clear, correct, and easy to maintain.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "d3ac309a",
"execution_count": null,
"outputs": [],
"source": [
"items_processed = 14\n",
"items_remaining = 6\n",
"\n",
"# TODO: write logic below that prints a helpful progress update for a teammate.\n",
"print(\"Add your progress update here.\")\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "893db52f",
"source": [
"## Exercise 5 — Explain your reasoning\n",
"\n",
"Write short answers in markdown or comments:\n",
"- Why is your solution readable?\n",
"- How could another developer understand it quickly?\n",
"- What edge case or mistake did you think about?\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "3f8fa4c5",
"source": [
"## Challenge set\n",
"\n",
"Try these without copying from earlier cells:\n",
"1. Solve a small version first.\n",
"2. Generalize your solution.\n",
"3. Test it with at least three different inputs.\n",
"4. Refactor any repeated logic.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "dc246e81",
"execution_count": null,
"outputs": [],
"source": [
"def challenge_task(data):\n",
" \"\"\"Replace this placeholder with your own solution for the challenge set.\"\"\"\n",
" return data\n",
"\n",
"print(challenge_task(\"start here\"))\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "053317e8",
"source": [
"## Topic-specific challenge ideas for Recursion\n",
"\n",
"Use the problems below as exam prep, portfolio prep, or interview-style practice.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "b17d68b7",
"source": [
"1. Trace a factorial function line by line.\n",
"2. Write a recursive sum-to-n function.\n",
"3. Compare a recursive countdown to a loop-based countdown.\n",
"4. Solve a nested-list counting problem.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "fb67f39b",
"source": [
"## Exam-prep mindset\n",
"\n",
"When preparing for major exams or technical interviews, do not just ask, “Can I memorize this?” Ask:\n",
"- Can I explain it clearly?\n",
"- Can I solve a fresh problem with it?\n",
"- Can I debug a broken version of it?\n",
"- Can I choose this approach for the right reason?\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "e5d3ef35",
"source": [
"## Career connection\n",
"\n",
"This week's practice is also training real workplace habits: clarity, testing, decomposition, communication, and disciplined thinking. Those habits matter in software engineering, data work, automation, QA, scripting, backend development, and many other roles.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "6a1f9aee",
"source": [
"## Self-check before moving on\n",
"\n",
"Rate yourself from 1 to 5 on each question:\n",
"- I can solve a straightforward problem from this topic without copying.\n",
"- I can explain the core idea to another learner.\n",
"- I can debug a small mistake in code from this topic.\n",
"- I can imagine a real-world use case for this topic.\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
================================================
FILE: week_6/0006_practice_exceptions.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"id": "11cab6a0",
"source": [
"# Week 6 Practice — Exceptions\n",
"\n",
"This practice notebook is designed to strengthen student thinking, not just student memory. The goal is to turn the week's lesson into repeatable skill.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "0df7d85a",
"source": [
"## Why this practice notebook matters\n",
"\n",
"In real jobs, developers are expected to do more than remember syntax. They must inspect data carefully, break problems into parts, explain their reasoning, and produce dependable solutions under pressure. These exercises are built to train those habits early.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "57f444f0",
"source": [
"## Focus areas\n",
"\n",
"- spotting failure points\n",
"- handling errors responsibly\n",
"- designing safer functions\n",
"- writing code that fails gracefully\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "7111f7f2",
"source": [
"## How to use this notebook\n",
"\n",
"1. Solve the warm-up tasks first.\n",
"2. Write your own answer before looking for patterns.\n",
"3. Test small pieces of code often.\n",
"4. Explain *why* your answer works.\n",
"5. Treat the challenge section like exam prep or interview prep.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "5d872ad6",
"source": [
"## Warm-up reflection\n",
"\n",
"Before coding, answer these questions in your own words:\n",
"- What is the main idea of this week's topic?\n",
"- What mistakes are beginners likely to make here?\n",
"- How might this topic appear in a real application or workplace task?\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "f7195ad2",
"execution_count": null,
"outputs": [],
"source": [
"# Warm-up starter for exceptions\n",
"notes = []\n",
"print(\"Use this cell to write quick notes or small experiments about exceptions.\")\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "f2c2b329",
"source": [
"## Exercise 1 — Read, predict, then run\n",
"\n",
"Read the code first. Predict the output on paper or in your head. Then run it and explain the result.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "ebb51dfa",
"execution_count": null,
"outputs": [],
"source": [
"sample_values = [3, 7, 10]\n",
"for value in sample_values:\n",
" print(value * 2)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "9b551bca",
"source": [
"### Your task\n",
"\n",
"Change the values, run the cell again, and explain what changed.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "df2e4de6",
"source": [
"## Exercise 2 — Complete the starter code\n",
"\n",
"Finish the code so that it solves a small realistic problem.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "b46cc874",
"execution_count": null,
"outputs": [],
"source": [
"project_name = \"Starter Project\"\n",
"completed_steps = 2\n",
"total_steps = 5\n",
"\n",
"# TODO: create a message that reports progress clearly.\n",
"# Example idea: \"Starter Project is 40% complete.\"\n",
"\n",
"message = \"Replace this text with your answer.\"\n",
"print(message)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "25e4425d",
"source": [
"## Exercise 3 — Debugging drill\n",
"\n",
"In real work, you often improve broken code instead of writing from scratch.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "d9cf18d0",
"execution_count": null,
"outputs": [],
"source": [
"def broken_example(number):\n",
" # TODO: fix the logic so the function returns a useful value.\n",
" result = number + 1\n",
" return result\n",
"\n",
"print(broken_example(5))\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "c0c0c632",
"source": [
"### Debugging questions\n",
"\n",
"- What is the code trying to do?\n",
"- Is the variable naming clear enough?\n",
"- How would you test your fix with more than one input?\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "4529c183",
"source": [
"## Exercise 4 — Real-world mini scenario\n",
"\n",
"Imagine you are building a tiny internal tool at work. The code does not need to be huge; it needs to be clear, correct, and easy to maintain.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "aa5d87ae",
"execution_count": null,
"outputs": [],
"source": [
"items_processed = 14\n",
"items_remaining = 6\n",
"\n",
"# TODO: write logic below that prints a helpful progress update for a teammate.\n",
"print(\"Add your progress update here.\")\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "c5ae9d1c",
"source": [
"## Exercise 5 — Explain your reasoning\n",
"\n",
"Write short answers in markdown or comments:\n",
"- Why is your solution readable?\n",
"- How could another developer understand it quickly?\n",
"- What edge case or mistake did you think about?\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "38d651b8",
"source": [
"## Challenge set\n",
"\n",
"Try these without copying from earlier cells:\n",
"1. Solve a small version first.\n",
"2. Generalize your solution.\n",
"3. Test it with at least three different inputs.\n",
"4. Refactor any repeated logic.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "045d235f",
"execution_count": null,
"outputs": [],
"source": [
"def challenge_task(data):\n",
" \"\"\"Replace this placeholder with your own solution for the challenge set.\"\"\"\n",
" return data\n",
"\n",
"print(challenge_task(\"start here\"))\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "095890f9",
"source": [
"## Topic-specific challenge ideas for Exceptions\n",
"\n",
"Use the problems below as exam prep, portfolio prep, or interview-style practice.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "6ba8d58d",
"source": [
"1. Safely convert strings to integers.\n",
"2. Handle division by zero in a function.\n",
"3. Decide which exception type fits a bad input case.\n",
"4. Write a user-friendly error message for invalid data.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "74fa2f82",
"source": [
"## Exam-prep mindset\n",
"\n",
"When preparing for major exams or technical interviews, do not just ask, “Can I memorize this?” Ask:\n",
"- Can I explain it clearly?\n",
"- Can I solve a fresh problem with it?\n",
"- Can I debug a broken version of it?\n",
"- Can I choose this approach for the right reason?\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "2de443f5",
"source": [
"## Career connection\n",
"\n",
"This week's practice is also training real workplace habits: clarity, testing, decomposition, communication, and disciplined thinking. Those habits matter in software engineering, data work, automation, QA, scripting, backend development, and many other roles.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "4706dd89",
"source": [
"## Self-check before moving on\n",
"\n",
"Rate yourself from 1 to 5 on each question:\n",
"- I can solve a straightforward problem from this topic without copying.\n",
"- I can explain the core idea to another learner.\n",
"- I can debug a small mistake in code from this topic.\n",
"- I can imagine a real-world use case for this topic.\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
================================================
FILE: week_6/try_except.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Exceptions and Error Handling\n",
"\n",
"Errors are part of programming. Strong programmers do not panic when code fails; they inspect the problem, handle it carefully, and improve the program.\n"
],
"id": "de1a83da"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Learning goals\n",
"\n",
"You will learn to:\n",
"- use `try` and `except`\n",
"- catch specific exceptions\n",
"- understand `else` and `finally`\n",
"- connect error handling to functions and user-facing messages\n"
],
"id": "12e21d43"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## A simple `try` / `except`\n"
],
"id": "193260bc"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"try:\n",
" value = int(\"42\")\n",
" print(value)\n",
"except ValueError:\n",
" print(\"That value could not be converted to an integer.\")\n"
],
"id": "bbe3a27a"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"try:\n",
" value = int(\"not-a-number\")\n",
" print(value)\n",
"except ValueError as error:\n",
" print(\"Conversion failed:\", error)\n"
],
"id": "1743a4ad"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Handling errors inside a function\n"
],
"id": "e04bde8d"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def parse_age(text):\n",
" try:\n",
" age = int(text)\n",
" return age\n",
" except ValueError as error:\n",
" raise RuntimeError(\"Age must be written as a whole number.\") from error\n",
"\n",
"try:\n",
" parse_age(\"twelve\")\n",
"except RuntimeError as error:\n",
" print(\"Handled error:\", error)\n",
" print(\"Original cause:\", error.__cause__)\n"
],
"id": "f13d9a33"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Reusing conditions with exceptions\n"
],
"id": "8bbb509d"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def safe_divide(numerator, denominator):\n",
" try:\n",
" result = numerator / denominator\n",
" except ZeroDivisionError:\n",
" return \"Cannot divide by zero.\"\n",
" else:\n",
" return f\"Result: {result}\"\n",
"\n",
"print(safe_divide(10, 2))\n",
"print(safe_divide(10, 0))\n"
],
"id": "cc4c67cc"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## `else` and `finally`\n"
],
"id": "baca0db8"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"try:\n",
" result = 10 / 2\n",
"except ZeroDivisionError:\n",
" print(\"Cannot divide by zero.\")\n",
"else:\n",
" print(\"Division worked:\", result)\n",
"finally:\n",
" print(\"This cleanup step always runs.\")\n"
],
"id": "2b7b26a4"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Why specificity matters\n",
"\n",
"Catch the narrowest exception that matches the problem you expect.\n"
],
"id": "aafb9427"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"data = [\"5\", \"12\", \"oops\", \"19\"]\n",
"for item in data:\n",
" try:\n",
" print(int(item) * 2)\n",
" except ValueError:\n",
" print(f\"Skipped invalid number: {item}\")\n"
],
"id": "84e27673"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Practice prompts\n",
"\n",
"1. Write a function that converts text to `float`.\n",
"2. Catch a `KeyError` from a dictionary lookup.\n",
"3. Explain the difference between `except` and `finally`.\n"
],
"id": "4dba8e11"
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
================================================
FILE: week_7/0007 Objects and Classes.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Objects and Classes\n",
"\n",
"Object-oriented programming helps us model real things in code. A class is a blueprint, and an object is a concrete instance created from that blueprint.\n"
],
"id": "8f6634b8"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Learning goals\n",
"\n",
"You will learn to:\n",
"- define classes with attributes and methods\n",
"- create multiple objects from one class\n",
"- connect classes to earlier topics such as strings, functions, and dictionaries\n"
],
"id": "617a8042"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Defining a class\n"
],
"id": "c8fcb7f3"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"source": [
"class Student:\n",
" \"\"\"Represent a student in a Python course.\"\"\"\n",
"\n",
" school_name = \"Bright Path Academy\"\n",
"\n",
" def __init__(self, name, level):\n",
" self.name = name\n",
" self.level = level\n",
"\n",
" def introduce(self):\n",
" print(f\"Hello, I am {self.name} and I am a {self.level} learner.\")\n"
],
"id": "ebfce109"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(Student.__doc__)\n",
"print(Student.school_name)\n"
],
"id": "86a42eb8"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Creating objects\n"
],
"id": "bb64763f"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"student_one = Student(\"Avery\", \"beginner\")\n",
"student_two = Student(\"Jordan\", \"intermediate\")\n",
"\n",
"student_one.introduce()\n",
"student_two.introduce()\n"
],
"id": "f462110b"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Updating object data\n"
],
"id": "87a66550"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"student_one.level = \"confident beginner\"\n",
"student_one.introduce()\n"
],
"id": "79c9b8a5"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Methods can use earlier Python skills\n"
],
"id": "cbd1fcbe"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class ProgressTracker:\n",
" def __init__(self, learner_name, completed_topics):\n",
" self.learner_name = learner_name\n",
" self.completed_topics = completed_topics\n",
"\n",
" def summary(self):\n",
" print(f\"{self.learner_name} completed {len(self.completed_topics)} topics.\")\n",
" for topic in self.completed_topics:\n",
" print(f\"- {topic}\")\n",
"\n",
"tracker = ProgressTracker(\"Avery\", [\"variables\", \"lists\", \"loops\"])\n",
"tracker.summary()\n"
],
"id": "c5934481"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Another realistic class example\n"
],
"id": "08dca369"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"source": [
"class BankAccount:\n",
" def __init__(self, owner, balance=0):\n",
" self.owner = owner\n",
" self.balance = balance\n",
"\n",
" def deposit(self, amount):\n",
" self.balance += amount\n",
" return self.balance\n",
"\n",
" def withdraw(self, amount):\n",
" if amount > self.balance:\n",
" return \"Insufficient funds\"\n",
" self.balance -= amount\n",
" return self.balance\n",
"\n",
"account = BankAccount(\"Avery\", 100)\n",
"print(account.deposit(25))\n",
"print(account.withdraw(80))\n",
"print(account.withdraw(100))\n"
],
"id": "4fffda77"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Objects can also return structured data\n"
],
"id": "1a5dcd25"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class Course:\n",
" def __init__(self, title, lesson_count):\n",
" self.title = title\n",
" self.lesson_count = lesson_count\n",
"\n",
" def as_dictionary(self):\n",
" return {\"title\": self.title, \"lesson_count\": self.lesson_count}\n",
"\n",
"course = Course(\"Python Foundations\", 8)\n",
"print(course.as_dictionary())\n"
],
"id": "5cc97076"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Practice prompts\n",
"\n",
"1. Create a `Book` class with `title` and `author`.\n",
"2. Add a method that prints a description.\n",
"3. Create two objects from the same class and compare their data.\n"
],
"id": "d15b3c98"
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
================================================
FILE: week_7/0007_practice_oop_basics.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"id": "5e2af90e",
"source": [
"# Week 7 Practice — Objects and Classes\n",
"\n",
"This practice notebook is designed to strengthen student thinking, not just student memory. The goal is to turn the week's lesson into repeatable skill.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "da2f3a00",
"source": [
"## Why this practice notebook matters\n",
"\n",
"In real jobs, developers are expected to do more than remember syntax. They must inspect data carefully, break problems into parts, explain their reasoning, and produce dependable solutions under pressure. These exercises are built to train those habits early.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "d6ca97ab",
"source": [
"## Focus areas\n",
"\n",
"- class design\n",
"- attributes and methods\n",
"- modeling simple real-world data\n",
"- thinking in objects instead of loose variables\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "ec8d290b",
"source": [
"## How to use this notebook\n",
"\n",
"1. Solve the warm-up tasks first.\n",
"2. Write your own answer before looking for patterns.\n",
"3. Test small pieces of code often.\n",
"4. Explain *why* your answer works.\n",
"5. Treat the challenge section like exam prep or interview prep.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "e07a45ea",
"source": [
"## Warm-up reflection\n",
"\n",
"Before coding, answer these questions in your own words:\n",
"- What is the main idea of this week's topic?\n",
"- What mistakes are beginners likely to make here?\n",
"- How might this topic appear in a real application or workplace task?\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "570347f3",
"execution_count": null,
"outputs": [],
"source": [
"# Warm-up starter for objects and classes\n",
"notes = []\n",
"print(\"Use this cell to write quick notes or small experiments about objects and classes.\")\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "6a593e25",
"source": [
"## Exercise 1 — Read, predict, then run\n",
"\n",
"Read the code first. Predict the output on paper or in your head. Then run it and explain the result.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "e04de071",
"execution_count": null,
"outputs": [],
"source": [
"sample_values = [3, 7, 10]\n",
"for value in sample_values:\n",
" print(value * 2)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "4efc6122",
"source": [
"### Your task\n",
"\n",
"Change the values, run the cell again, and explain what changed.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "d440340c",
"source": [
"## Exercise 2 — Complete the starter code\n",
"\n",
"Finish the code so that it solves a small realistic problem.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "e0827a5a",
"execution_count": null,
"outputs": [],
"source": [
"project_name = \"Starter Project\"\n",
"completed_steps = 2\n",
"total_steps = 5\n",
"\n",
"# TODO: create a message that reports progress clearly.\n",
"# Example idea: \"Starter Project is 40% complete.\"\n",
"\n",
"message = \"Replace this text with your answer.\"\n",
"print(message)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "356df04b",
"source": [
"## Exercise 3 — Debugging drill\n",
"\n",
"In real work, you often improve broken code instead of writing from scratch.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "342beaca",
"execution_count": null,
"outputs": [],
"source": [
"def broken_example(number):\n",
" # TODO: fix the logic so the function returns a useful value.\n",
" result = number + 1\n",
" return result\n",
"\n",
"print(broken_example(5))\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "e7c7c8e1",
"source": [
"### Debugging questions\n",
"\n",
"- What is the code trying to do?\n",
"- Is the variable naming clear enough?\n",
"- How would you test your fix with more than one input?\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "32b9b1fd",
"source": [
"## Exercise 4 — Real-world mini scenario\n",
"\n",
"Imagine you are building a tiny internal tool at work. The code does not need to be huge; it needs to be clear, correct, and easy to maintain.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "a0c0673f",
"execution_count": null,
"outputs": [],
"source": [
"items_processed = 14\n",
"items_remaining = 6\n",
"\n",
"# TODO: write logic below that prints a helpful progress update for a teammate.\n",
"print(\"Add your progress update here.\")\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "f58d7963",
"source": [
"## Exercise 5 — Explain your reasoning\n",
"\n",
"Write short answers in markdown or comments:\n",
"- Why is your solution readable?\n",
"- How could another developer understand it quickly?\n",
"- What edge case or mistake did you think about?\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "2c3d704d",
"source": [
"## Challenge set\n",
"\n",
"Try these without copying from earlier cells:\n",
"1. Solve a small version first.\n",
"2. Generalize your solution.\n",
"3. Test it with at least three different inputs.\n",
"4. Refactor any repeated logic.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "7789c87c",
"execution_count": null,
"outputs": [],
"source": [
"def challenge_task(data):\n",
" \"\"\"Replace this placeholder with your own solution for the challenge set.\"\"\"\n",
" return data\n",
"\n",
"print(challenge_task(\"start here\"))\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "55706e5c",
"source": [
"## Topic-specific challenge ideas for Objects And Classes\n",
"\n",
"Use the problems below as exam prep, portfolio prep, or interview-style practice.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "e770c3d0",
"source": [
"1. Design a `Book` or `Employee` class.\n",
"2. Add a method that prints a clean summary.\n",
"3. Compare using a dictionary versus using a class.\n",
"4. Think about what data belongs together in one object.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "a48090d0",
"source": [
"## Exam-prep mindset\n",
"\n",
"When preparing for major exams or technical interviews, do not just ask, “Can I memorize this?” Ask:\n",
"- Can I explain it clearly?\n",
"- Can I solve a fresh problem with it?\n",
"- Can I debug a broken version of it?\n",
"- Can I choose this approach for the right reason?\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "cefe711e",
"source": [
"## Career connection\n",
"\n",
"This week's practice is also training real workplace habits: clarity, testing, decomposition, communication, and disciplined thinking. Those habits matter in software engineering, data work, automation, QA, scripting, backend development, and many other roles.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "5e247169",
"source": [
"## Self-check before moving on\n",
"\n",
"Rate yourself from 1 to 5 on each question:\n",
"- I can solve a straightforward problem from this topic without copying.\n",
"- I can explain the core idea to another learner.\n",
"- I can debug a small mistake in code from this topic.\n",
"- I can imagine a real-world use case for this topic.\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
================================================
FILE: week_8/0008 Inheritance Basics.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Inheritance Basics\n",
"\n",
"Inheritance lets one class reuse and extend another class.\n"
],
"id": "3711a158"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Learning goals\n",
"\n",
"You will learn to:\n",
"- define parent and child classes\n",
"- reuse parent behavior with `super()`\n",
"- connect inheritance to methods, attributes, and object creation from the previous notebook\n"
],
"id": "1aeb006c"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## A parent class\n"
],
"id": "de497d8e"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class Person:\n",
" def __init__(self, name, role):\n",
" self.name = name\n",
" self.role = role\n",
"\n",
" def describe(self):\n",
" print(f\"{self.name} works as a {self.role}.\")\n"
],
"id": "2cfdaed6"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Child class: Instructor\n"
],
"id": "29461a1a"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class Instructor(Person):\n",
" def __init__(self, name, topic):\n",
" super().__init__(name, \"instructor\")\n",
" self.topic = topic\n",
"\n",
" def teach(self):\n",
" print(f\"{self.name} is teaching {self.topic}.\")\n"
],
"id": "da764154"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Child class: Learner\n"
],
"id": "89cd3e1f"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class Learner(Person):\n",
" def __init__(self, name, current_topic):\n",
" super().__init__(name, \"learner\")\n",
" self.current_topic = current_topic\n",
"\n",
" def study(self):\n",
" print(f\"{self.name} is studying {self.current_topic}.\")\n"
],
"id": "ca647acb"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Using the classes\n"
],
"id": "6668668d"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"instructor = Instructor(\"River\", \"Python basics\")\n",
"learner = Learner(\"Avery\", \"functions\")\n",
"\n",
"instructor.describe()\n",
"instructor.teach()\n",
"learner.describe()\n",
"learner.study()\n"
],
"id": "4d5753fb"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Why `super()` matters\n",
"\n",
"`super()` allows the child class to reuse the parent initialization cleanly.\n"
],
"id": "2cdba58a"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(isinstance(instructor, Instructor))\n",
"print(isinstance(instructor, Person))\n"
],
"id": "b0e9b646"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Extending inherited behavior\n"
],
"id": "012aef97"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class TeachingAssistant(Learner):\n",
" def __init__(self, name, current_topic, hours_helped):\n",
" super().__init__(name, current_topic)\n",
" self.hours_helped = hours_helped\n",
"\n",
" def support(self):\n",
" print(f\"{self.name} helped other learners for {self.hours_helped} hours.\")\n",
"\n",
"assistant = TeachingAssistant(\"Jordan\", \"loops\", 4)\n",
"assistant.describe()\n",
"assistant.study()\n",
"assistant.support()\n"
],
"id": "816e625a"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Practice prompts\n",
"\n",
"1. Create a parent class called `Vehicle`.\n",
"2. Create child classes such as `Car` and `Bike`.\n",
"3. Add one shared method and one unique method.\n"
],
"id": "6626ac8a"
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
================================================
FILE: week_8/0008_practice_inheritance.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"id": "59c2742b",
"source": [
"# Week 8 Practice — Inheritance\n",
"\n",
"This practice notebook is designed to strengthen student thinking, not just student memory. The goal is to turn the week's lesson into repeatable skill.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "35ef9e0a",
"source": [
"## Why this practice notebook matters\n",
"\n",
"In real jobs, developers are expected to do more than remember syntax. They must inspect data carefully, break problems into parts, explain their reasoning, and produce dependable solutions under pressure. These exercises are built to train those habits early.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "4548a7cb",
"source": [
"## Focus areas\n",
"\n",
"- parent and child classes\n",
"- shared behavior vs unique behavior\n",
"- super()\n",
"- designing class hierarchies carefully\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "f0c5258c",
"source": [
"## How to use this notebook\n",
"\n",
"1. Solve the warm-up tasks first.\n",
"2. Write your own answer before looking for patterns.\n",
"3. Test small pieces of code often.\n",
"4. Explain *why* your answer works.\n",
"5. Treat the challenge section like exam prep or interview prep.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "289aadf2",
"source": [
"## Warm-up reflection\n",
"\n",
"Before coding, answer these questions in your own words:\n",
"- What is the main idea of this week's topic?\n",
"- What mistakes are beginners likely to make here?\n",
"- How might this topic appear in a real application or workplace task?\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "c61aa222",
"execution_count": null,
"outputs": [],
"source": [
"# Warm-up starter for inheritance\n",
"notes = []\n",
"print(\"Use this cell to write quick notes or small experiments about inheritance.\")\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "21e3d01f",
"source": [
"## Exercise 1 — Read, predict, then run\n",
"\n",
"Read the code first. Predict the output on paper or in your head. Then run it and explain the result.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "d60f5054",
"execution_count": null,
"outputs": [],
"source": [
"sample_values = [3, 7, 10]\n",
"for value in sample_values:\n",
" print(value * 2)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "13bbe1ce",
"source": [
"### Your task\n",
"\n",
"Change the values, run the cell again, and explain what changed.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "f36abf48",
"source": [
"## Exercise 2 — Complete the starter code\n",
"\n",
"Finish the code so that it solves a small realistic problem.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "72e9de7d",
"execution_count": null,
"outputs": [],
"source": [
"project_name = \"Starter Project\"\n",
"completed_steps = 2\n",
"total_steps = 5\n",
"\n",
"# TODO: create a message that reports progress clearly.\n",
"# Example idea: \"Starter Project is 40% complete.\"\n",
"\n",
"message = \"Replace this text with your answer.\"\n",
"print(message)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "4cd2ea2a",
"source": [
"## Exercise 3 — Debugging drill\n",
"\n",
"In real work, you often improve broken code instead of writing from scratch.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "760a7bd6",
"execution_count": null,
"outputs": [],
"source": [
"def broken_example(number):\n",
" # TODO: fix the logic so the function returns a useful value.\n",
" result = number + 1\n",
" return result\n",
"\n",
"print(broken_example(5))\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "f0a1d239",
"source": [
"### Debugging questions\n",
"\n",
"- What is the code trying to do?\n",
"- Is the variable naming clear enough?\n",
"- How would you test your fix with more than one input?\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "dc87ee73",
"source": [
"## Exercise 4 — Real-world mini scenario\n",
"\n",
"Imagine you are building a tiny internal tool at work. The code does not need to be huge; it needs to be clear, correct, and easy to maintain.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "0d9b40f8",
"execution_count": null,
"outputs": [],
"source": [
"items_processed = 14\n",
"items_remaining = 6\n",
"\n",
"# TODO: write logic below that prints a helpful progress update for a teammate.\n",
"print(\"Add your progress update here.\")\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "31a8c91e",
"source": [
"## Exercise 5 — Explain your reasoning\n",
"\n",
"Write short answers in markdown or comments:\n",
"- Why is your solution readable?\n",
"- How could another developer understand it quickly?\n",
"- What edge case or mistake did you think about?\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "6be228d3",
"source": [
"## Challenge set\n",
"\n",
"Try these without copying from earlier cells:\n",
"1. Solve a small version first.\n",
"2. Generalize your solution.\n",
"3. Test it with at least three different inputs.\n",
"4. Refactor any repeated logic.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "1d60db4c",
"execution_count": null,
"outputs": [],
"source": [
"def challenge_task(data):\n",
" \"\"\"Replace this placeholder with your own solution for the challenge set.\"\"\"\n",
" return data\n",
"\n",
"print(challenge_task(\"start here\"))\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "3d06052e",
"source": [
"## Topic-specific challenge ideas for Inheritance\n",
"\n",
"Use the problems below as exam prep, portfolio prep, or interview-style practice.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "e4a0e6ac",
"source": [
"1. Create a `Vehicle` parent class and two child classes.\n",
"2. Move repeated code into the parent class.\n",
"3. Use `super()` correctly in child constructors.\n",
"4. Explain when inheritance helps and when it may be unnecessary.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "24ff1f96",
"source": [
"## Exam-prep mindset\n",
"\n",
"When preparing for major exams or technical interviews, do not just ask, “Can I memorize this?” Ask:\n",
"- Can I explain it clearly?\n",
"- Can I solve a fresh problem with it?\n",
"- Can I debug a broken version of it?\n",
"- Can I choose this approach for the right reason?\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "ced5c5db",
"source": [
"## Career connection\n",
"\n",
"This week's practice is also training real workplace habits: clarity, testing, decomposition, communication, and disciplined thinking. Those habits matter in software engineering, data work, automation, QA, scripting, backend development, and many other roles.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "15186479",
"source": [
"## Self-check before moving on\n",
"\n",
"Rate yourself from 1 to 5 on each question:\n",
"- I can solve a straightforward problem from this topic without copying.\n",
"- I can explain the core idea to another learner.\n",
"- I can debug a small mistake in code from this topic.\n",
"- I can imagine a real-world use case for this topic.\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
================================================
FILE: week_9/0009_practice_relationships.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"id": "af472c7c",
"source": [
"# Week 9 Practice — Object Relationships\n",
"\n",
"This practice notebook is designed to strengthen student thinking, not just student memory. The goal is to turn the week's lesson into repeatable skill.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "7ec0780b",
"source": [
"## Why this practice notebook matters\n",
"\n",
"In real jobs, developers are expected to do more than remember syntax. They must inspect data carefully, break problems into parts, explain their reasoning, and produce dependable solutions under pressure. These exercises are built to train those habits early.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "cb59bdc2",
"source": [
"## Focus areas\n",
"\n",
"- association, aggregation, and composition\n",
"- reading class relationships\n",
"- modeling systems like a software engineer\n",
"- reasoning about ownership and reuse\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "b19d8eb0",
"source": [
"## How to use this notebook\n",
"\n",
"1. Solve the warm-up tasks first.\n",
"2. Write your own answer before looking for patterns.\n",
"3. Test small pieces of code often.\n",
"4. Explain *why* your answer works.\n",
"5. Treat the challenge section like exam prep or interview prep.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "9ae11591",
"source": [
"## Warm-up reflection\n",
"\n",
"Before coding, answer these questions in your own words:\n",
"- What is the main idea of this week's topic?\n",
"- What mistakes are beginners likely to make here?\n",
"- How might this topic appear in a real application or workplace task?\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "a839a312",
"execution_count": null,
"outputs": [],
"source": [
"# Warm-up starter for object relationships\n",
"notes = []\n",
"print(\"Use this cell to write quick notes or small experiments about object relationships.\")\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "35912866",
"source": [
"## Exercise 1 — Read, predict, then run\n",
"\n",
"Read the code first. Predict the output on paper or in your head. Then run it and explain the result.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "c46a056a",
"execution_count": null,
"outputs": [],
"source": [
"sample_values = [3, 7, 10]\n",
"for value in sample_values:\n",
" print(value * 2)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "124df15b",
"source": [
"### Your task\n",
"\n",
"Change the values, run the cell again, and explain what changed.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "45b33d83",
"source": [
"## Exercise 2 — Complete the starter code\n",
"\n",
"Finish the code so that it solves a small realistic problem.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "a215df42",
"execution_count": null,
"outputs": [],
"source": [
"project_name = \"Starter Project\"\n",
"completed_steps = 2\n",
"total_steps = 5\n",
"\n",
"# TODO: create a message that reports progress clearly.\n",
"# Example idea: \"Starter Project is 40% complete.\"\n",
"\n",
"message = \"Replace this text with your answer.\"\n",
"print(message)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "10169106",
"source": [
"## Exercise 3 — Debugging drill\n",
"\n",
"In real work, you often improve broken code instead of writing from scratch.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "eac33935",
"execution_count": null,
"outputs": [],
"source": [
"def broken_example(number):\n",
" # TODO: fix the logic so the function returns a useful value.\n",
" result = number + 1\n",
" return result\n",
"\n",
"print(broken_example(5))\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "5f28613c",
"source": [
"### Debugging questions\n",
"\n",
"- What is the code trying to do?\n",
"- Is the variable naming clear enough?\n",
"- How would you test your fix with more than one input?\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "cf883bd7",
"source": [
"## Exercise 4 — Real-world mini scenario\n",
"\n",
"Imagine you are building a tiny internal tool at work. The code does not need to be huge; it needs to be clear, correct, and easy to maintain.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "d1b11fd0",
"execution_count": null,
"outputs": [],
"source": [
"items_processed = 14\n",
"items_remaining = 6\n",
"\n",
"# TODO: write logic below that prints a helpful progress update for a teammate.\n",
"print(\"Add your progress update here.\")\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "53b92654",
"source": [
"## Exercise 5 — Explain your reasoning\n",
"\n",
"Write short answers in markdown or comments:\n",
"- Why is your solution readable?\n",
"- How could another developer understand it quickly?\n",
"- What edge case or mistake did you think about?\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "1775cb38",
"source": [
"## Challenge set\n",
"\n",
"Try these without copying from earlier cells:\n",
"1. Solve a small version first.\n",
"2. Generalize your solution.\n",
"3. Test it with at least three different inputs.\n",
"4. Refactor any repeated logic.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "094f4ee9",
"execution_count": null,
"outputs": [],
"source": [
"def challenge_task(data):\n",
" \"\"\"Replace this placeholder with your own solution for the challenge set.\"\"\"\n",
" return data\n",
"\n",
"print(challenge_task(\"start here\"))\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "0a29d7db",
"source": [
"## Topic-specific challenge ideas for Object Relationships\n",
"\n",
"Use the problems below as exam prep, portfolio prep, or interview-style practice.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "72c07c0e",
"source": [
"1. Model a school, class, and student relationship.\n",
"2. Explain whether each relationship is association, aggregation, or composition.\n",
"3. Reuse a shared object in aggregation.\n",
"4. Show how composition creates tighter ownership.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "a32be9f0",
"source": [
"## Exam-prep mindset\n",
"\n",
"When preparing for major exams or technical interviews, do not just ask, “Can I memorize this?” Ask:\n",
"- Can I explain it clearly?\n",
"- Can I solve a fresh problem with it?\n",
"- Can I debug a broken version of it?\n",
"- Can I choose this approach for the right reason?\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "46ead5ab",
"source": [
"## Career connection\n",
"\n",
"This week's practice is also training real workplace habits: clarity, testing, decomposition, communication, and disciplined thinking. Those habits matter in software engineering, data work, automation, QA, scripting, backend development, and many other roles.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "3232f92e",
"source": [
"## Self-check before moving on\n",
"\n",
"Rate yourself from 1 to 5 on each question:\n",
"- I can solve a straightforward problem from this topic without copying.\n",
"- I can explain the core idea to another learner.\n",
"- I can debug a small mistake in code from this topic.\n",
"- I can imagine a real-world use case for this topic.\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
================================================
FILE: week_9/aggregation.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Hardware Modeling with Classes\n",
"\n",
"This notebook uses simple hardware-style examples to practice object relationships. The goal is to make the object design easy to understand, not to simulate hardware perfectly.\n"
],
"id": "2085c7e1"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class CPU:\n",
" def __init__(self, model, clock_speed_ghz, cores):\n",
" self.model = model\n",
" self.clock_speed_ghz = clock_speed_ghz\n",
" self.cores = cores\n",
"\n",
" def summary(self):\n",
" return f\"CPU: {self.model}, {self.cores} cores at {self.clock_speed_ghz} GHz\"\n",
"\n",
"\n",
"class RAM:\n",
" def __init__(self, capacity_gb, speed_mhz):\n",
" self.capacity_gb = capacity_gb\n",
" self.speed_mhz = speed_mhz\n",
"\n",
" def summary(self):\n",
" return f\"RAM: {self.capacity_gb} GB at {self.speed_mhz} MHz\"\n",
"\n",
"\n",
"class Storage:\n",
" def __init__(self, kind, capacity_gb):\n",
" self.kind = kind\n",
" self.capacity_gb = capacity_gb\n",
"\n",
" def summary(self):\n",
" return f\"Storage: {self.capacity_gb} GB {self.kind}\"\n"
],
"id": "4c6f341e"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Aggregation\n",
"\n",
"In aggregation, a larger object uses smaller objects that may already exist on their own.\n"
],
"id": "c0933af6"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class Computer:\n",
" def __init__(self, cpu, ram, storage):\n",
" self.cpu = cpu\n",
" self.ram = ram\n",
" self.storage = storage\n",
"\n",
" def summary(self):\n",
" print(self.cpu.summary())\n",
" print(self.ram.summary())\n",
" print(self.storage.summary())\n",
"\n",
"shared_cpu = CPU(\"StudyChip A1\", 3.2, 8)\n",
"shared_ram = RAM(16, 3200)\n",
"shared_storage = Storage(\"SSD\", 512)\n",
"\n",
"workstation = Computer(shared_cpu, shared_ram, shared_storage)\n",
"workstation.summary()\n"
],
"id": "0633139c"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Reusing shared parts\n"
],
"id": "588c52da"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"source": [
"backup_machine = Computer(shared_cpu, RAM(8, 2666), shared_storage)\n",
"backup_machine.summary()\n"
],
"id": "e6dfc572"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Key idea\n",
"\n",
"The parts are created first and then supplied to the larger object. That is the core of aggregation.\n"
],
"id": "05dfddf0"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Practice prompts\n",
"\n",
"1. Create another `Computer` with some shared parts.\n",
"2. Compare this design to composition.\n",
"3. Explain which objects could continue to exist even if the computer object were deleted.\n"
],
"id": "5c09c2f1"
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
================================================
FILE: week_9/association.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Association\n",
"\n",
"Association describes a relationship between objects that know about each other, but neither object necessarily owns the other.\n"
],
"id": "ac2b406c"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Learning goals\n",
"\n",
"You will learn to:\n",
"- model connected objects\n",
"- recognize when objects are related but not owned\n",
"- reuse class design skills from previous notebooks\n"
],
"id": "d7fc0eca"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class Address:\n",
" def __init__(self, street, city, postal_code):\n",
" self.street = street\n",
" self.city = city\n",
" self.postal_code = postal_code\n",
"\n",
" def formatted(self):\n",
" return f\"{self.street}, {self.city}, {self.postal_code}\"\n",
"\n",
"\n",
"class Person:\n",
" def __init__(self, name, address):\n",
" self.name = name\n",
" self.address = address\n",
"\n",
" def introduce(self):\n",
" print(f\"Hello, I am {self.name}.\")\n",
"\n",
" def show_address(self):\n",
" print(self.address.formatted())\n"
],
"id": "740636d8"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"home_address = Address(\"15 Garden Lane\", \"Maple Town\", \"40210\")\n",
"resident = Person(\"Avery\", home_address)\n",
"\n",
"resident.introduce()\n",
"resident.show_address()\n"
],
"id": "822f3343"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Another association example\n"
],
"id": "a9ed9121"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class Course:\n",
" def __init__(self, title):\n",
" self.title = title\n",
"\n",
"\n",
"class Teacher:\n",
" def __init__(self, name, course):\n",
" self.name = name\n",
" self.course = course\n",
"\n",
" def teach(self):\n",
" print(f\"{self.name} teaches {self.course.title}.\")\n",
"\n",
"python_course = Course(\"Python Foundations\")\n",
"teacher = Teacher(\"Jordan\", python_course)\n",
"teacher.teach()\n"
],
"id": "00bceca8"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## What to notice\n",
"\n",
"The `Person` is related to an `Address`, and the `Teacher` is related to a `Course`, but those related objects can also exist independently.\n"
],
"id": "f579f8b2"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Practice prompts\n",
"\n",
"1. Model an association between a `Doctor` and a `Hospital`.\n",
"2. Model an association between a `Coach` and a `Team`.\n",
"3. Explain why this is not composition.\n"
],
"id": "ecf60b19"
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
================================================
FILE: week_9/composition.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Hardware Modeling with Classes\n",
"\n",
"This notebook uses simple hardware-style examples to practice object relationships. The goal is to make the object design easy to understand, not to simulate hardware perfectly.\n"
],
"id": "688c00ca"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class CPU:\n",
" def __init__(self, model, clock_speed_ghz, cores):\n",
" self.model = model\n",
" self.clock_speed_ghz = clock_speed_ghz\n",
" self.cores = cores\n",
"\n",
" def summary(self):\n",
" return f\"CPU: {self.model}, {self.cores} cores at {self.clock_speed_ghz} GHz\"\n",
"\n",
"\n",
"class RAM:\n",
" def __init__(self, capacity_gb, speed_mhz):\n",
" self.capacity_gb = capacity_gb\n",
" self.speed_mhz = speed_mhz\n",
"\n",
" def summary(self):\n",
" return f\"RAM: {self.capacity_gb} GB at {self.speed_mhz} MHz\"\n",
"\n",
"\n",
"class Storage:\n",
" def __init__(self, kind, capacity_gb):\n",
" self.kind = kind\n",
" self.capacity_gb = capacity_gb\n",
"\n",
" def summary(self):\n",
" return f\"Storage: {self.capacity_gb} GB {self.kind}\"\n"
],
"id": "d75765e1"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Composition\n",
"\n",
"In composition, the larger object creates and owns its parts directly.\n"
],
"id": "107ff9dd"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class Computer:\n",
" def __init__(self):\n",
" self.cpu = CPU(\"StudyChip A1\", 3.2, 8)\n",
" self.ram = RAM(16, 3200)\n",
" self.storage = Storage(\"SSD\", 512)\n",
"\n",
" def summary(self):\n",
" print(self.cpu.summary())\n",
" print(self.ram.summary())\n",
" print(self.storage.summary())\n",
"\n",
"computer = Computer()\n",
"computer.summary()\n"
],
"id": "91841594"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Extending the design\n"
],
"id": "1e0d1ff4"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class GamingComputer(Computer):\n",
" def __init__(self):\n",
" super().__init__()\n",
" self.storage = Storage(\"NVMe SSD\", 1024)\n",
"\n",
"powerful_machine = GamingComputer()\n",
"powerful_machine.summary()\n"
],
"id": "b0f33f5d"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Key idea\n",
"\n",
"The parts are created inside the larger object, so ownership is much tighter than in aggregation.\n"
],
"id": "724f8c04"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Practice prompts\n",
"\n",
"1. Add a display component to the class.\n",
"2. Add a method that returns a dictionary summary.\n",
"3. Compare this notebook directly with aggregation.\n"
],
"id": "f20b5a60"
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
================================================
FILE: week_9/mixin..ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Mixins\n",
"\n",
"A mixin is a small class that adds one focused behavior to another class.\n"
],
"id": "dc1053b0"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Learning goals\n",
"\n",
"You will learn to:\n",
"- identify what a mixin should and should not do\n",
"- add narrow reusable behavior to another class\n",
"- keep inheritance design simple and intentional\n"
],
"id": "482c6e8b"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class TimestampMixin:\n",
" def record_event(self, event_name):\n",
" from datetime import datetime\n",
" print(f\"[{datetime.now().isoformat(timespec='seconds')}] {event_name}\")\n",
"\n",
"\n",
"class Project(TimestampMixin):\n",
" def __init__(self, title):\n",
" self.title = title\n",
"\n",
" def start(self):\n",
" self.record_event(f\"Project '{self.title}' started\")\n",
"\n",
"project = Project(\"Weather Dashboard\")\n",
"project.start()\n"
],
"id": "967d82ad"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Another focused mixin\n"
],
"id": "9fb85f4f"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class DisplayNameMixin:\n",
" def display_name(self):\n",
" print(f\"Name: {self.name}\")\n",
"\n",
"\n",
"class TeamMember(DisplayNameMixin):\n",
" def __init__(self, name, role):\n",
" self.name = name\n",
" self.role = role\n",
"\n",
"member = TeamMember(\"Riley\", \"tester\")\n",
"member.display_name()\n"
],
"id": "fcd1a5f7"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Mixins should stay small\n",
"\n",
"A mixin should usually contribute one narrow capability, such as logging, naming, formatting, or validation.\n"
],
"id": "c8287607"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class ActiveStateMixin:\n",
" def is_active(self):\n",
" return self.active\n",
"\n",
"\n",
"class Service(ActiveStateMixin):\n",
" def __init__(self, name, active):\n",
" self.name = name\n",
" self.active = active\n",
"\n",
"service = Service(\"Email Service\", True)\n",
"print(service.is_active())\n"
],
"id": "f6d6a617"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Practice prompts\n",
"\n",
"1. Create a mixin that formats text as uppercase.\n",
"2. Use it in another class.\n",
"3. Explain why the mixin should stay small.\n"
],
"id": "d56786f7"
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
================================================
FILE: week_x/0010_practice_oop_design.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"id": "a505496f",
"source": [
"# Week X Practice — Encapsulation, Polymorphism, and Abstraction\n",
"\n",
"This practice notebook is designed to strengthen student thinking, not just student memory. The goal is to turn the week's lesson into repeatable skill.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "386dabb4",
"source": [
"## Why this practice notebook matters\n",
"\n",
"In real jobs, developers are expected to do more than remember syntax. They must inspect data carefully, break problems into parts, explain their reasoning, and produce dependable solutions under pressure. These exercises are built to train those habits early.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "56db6cc6",
"source": [
"## Focus areas\n",
"\n",
"- encapsulation decisions\n",
"- polymorphic interfaces\n",
"- abstract base classes\n",
"- designing software with cleaner boundaries\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "c33b1436",
"source": [
"## How to use this notebook\n",
"\n",
"1. Solve the warm-up tasks first.\n",
"2. Write your own answer before looking for patterns.\n",
"3. Test small pieces of code often.\n",
"4. Explain *why* your answer works.\n",
"5. Treat the challenge section like exam prep or interview prep.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "5d8f2d22",
"source": [
"## Warm-up reflection\n",
"\n",
"Before coding, answer these questions in your own words:\n",
"- What is the main idea of this week's topic?\n",
"- What mistakes are beginners likely to make here?\n",
"- How might this topic appear in a real application or workplace task?\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "095276c9",
"execution_count": null,
"outputs": [],
"source": [
"# Warm-up starter for advanced OOP thinking\n",
"notes = []\n",
"print(\"Use this cell to write quick notes or small experiments about advanced OOP thinking.\")\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "737710c9",
"source": [
"## Exercise 1 — Read, predict, then run\n",
"\n",
"Read the code first. Predict the output on paper or in your head. Then run it and explain the result.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "76bddf76",
"execution_count": null,
"outputs": [],
"source": [
"sample_values = [3, 7, 10]\n",
"for value in sample_values:\n",
" print(value * 2)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "c5d3db89",
"source": [
"### Your task\n",
"\n",
"Change the values, run the cell again, and explain what changed.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "fe910926",
"source": [
"## Exercise 2 — Complete the starter code\n",
"\n",
"Finish the code so that it solves a small realistic problem.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "e450a795",
"execution_count": null,
"outputs": [],
"source": [
"project_name = \"Starter Project\"\n",
"completed_steps = 2\n",
"total_steps = 5\n",
"\n",
"# TODO: create a message that reports progress clearly.\n",
"# Example idea: \"Starter Project is 40% complete.\"\n",
"\n",
"message = \"Replace this text with your answer.\"\n",
"print(message)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "851526df",
"source": [
"## Exercise 3 — Debugging drill\n",
"\n",
"In real work, you often improve broken code instead of writing from scratch.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "4baac8f0",
"execution_count": null,
"outputs": [],
"source": [
"def broken_example(number):\n",
" # TODO: fix the logic so the function returns a useful value.\n",
" result = number + 1\n",
" return result\n",
"\n",
"print(broken_example(5))\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "e9006142",
"source": [
"### Debugging questions\n",
"\n",
"- What is the code trying to do?\n",
"- Is the variable naming clear enough?\n",
"- How would you test your fix with more than one input?\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "ff8b9d75",
"source": [
"## Exercise 4 — Real-world mini scenario\n",
"\n",
"Imagine you are building a tiny internal tool at work. The code does not need to be huge; it needs to be clear, correct, and easy to maintain.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "03f156e7",
"execution_count": null,
"outputs": [],
"source": [
"items_processed = 14\n",
"items_remaining = 6\n",
"\n",
"# TODO: write logic below that prints a helpful progress update for a teammate.\n",
"print(\"Add your progress update here.\")\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "b6c52379",
"source": [
"## Exercise 5 — Explain your reasoning\n",
"\n",
"Write short answers in markdown or comments:\n",
"- Why is your solution readable?\n",
"- How could another developer understand it quickly?\n",
"- What edge case or mistake did you think about?\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "f9691a06",
"source": [
"## Challenge set\n",
"\n",
"Try these without copying from earlier cells:\n",
"1. Solve a small version first.\n",
"2. Generalize your solution.\n",
"3. Test it with at least three different inputs.\n",
"4. Refactor any repeated logic.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "6f2d8200",
"execution_count": null,
"outputs": [],
"source": [
"def challenge_task(data):\n",
" \"\"\"Replace this placeholder with your own solution for the challenge set.\"\"\"\n",
" return data\n",
"\n",
"print(challenge_task(\"start here\"))\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "451c5348",
"source": [
"## Topic-specific challenge ideas for Advanced Oop Thinking\n",
"\n",
"Use the problems below as exam prep, portfolio prep, or interview-style practice.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "3d597257",
"source": [
"1. Protect a field with encapsulation.\n",
"2. Write multiple classes that respond to the same method name.\n",
"3. Create an abstract base class for a shared interface.\n",
"4. Explain why cleaner design makes team software easier to maintain.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "8980819a",
"source": [
"## Exam-prep mindset\n",
"\n",
"When preparing for major exams or technical interviews, do not just ask, “Can I memorize this?” Ask:\n",
"- Can I explain it clearly?\n",
"- Can I solve a fresh problem with it?\n",
"- Can I debug a broken version of it?\n",
"- Can I choose this approach for the right reason?\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "bb438dc6",
"source": [
"## Career connection\n",
"\n",
"This week's practice is also training real workplace habits: clarity, testing, decomposition, communication, and disciplined thinking. Those habits matter in software engineering, data work, automation, QA, scripting, backend development, and many other roles.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "c51a60cf",
"source": [
"## Self-check before moving on\n",
"\n",
"Rate yourself from 1 to 5 on each question:\n",
"- I can solve a straightforward problem from this topic without copying.\n",
"- I can explain the core idea to another learner.\n",
"- I can debug a small mistake in code from this topic.\n",
"- I can imagine a real-world use case for this topic.\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
================================================
FILE: week_x/abstraction.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Abstraction\n",
"\n",
"Abstraction lets us describe what a class must do without deciding every detail immediately.\n"
],
"id": "fba4a5fe"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Learning goals\n",
"\n",
"You will learn to:\n",
"- define abstract base classes\n",
"- require child classes to implement specific methods\n",
"- connect abstraction to polymorphism and inheritance\n"
],
"id": "306afd7c"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from abc import ABC, abstractmethod\n",
"\n",
"\n",
"class Notification(ABC):\n",
" @abstractmethod\n",
" def send(self, message):\n",
" \"\"\"Send a message using a concrete notification channel.\"\"\"\n"
],
"id": "d3b2b8a0"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## A concrete implementation\n"
],
"id": "575c49d5"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"source": [
"class EmailNotification(Notification):\n",
" def send(self, message):\n",
" print(f\"Email sent: {message}\")\n",
"\n",
"email_notification = EmailNotification()\n",
"email_notification.send(\"Your project build finished successfully.\")\n"
],
"id": "9c5bb878"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Another implementation\n"
],
"id": "6a7b8837"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class SMSNotification(Notification):\n",
" def send(self, message):\n",
" print(f\"SMS sent: {message}\")\n",
"\n",
"for service in [EmailNotification(), SMSNotification()]:\n",
" service.send(\"Daily reminder: keep practicing Python.\")\n"
],
"id": "1e218e13"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Connection to polymorphism\n",
"\n",
"Abstraction defines the required behavior. Polymorphism lets different child classes fulfill that behavior in their own way.\n"
],
"id": "d8ac49a2"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"source": [
"def send_all(notifiers, message):\n",
" for notifier in notifiers:\n",
" notifier.send(message)\n",
"\n",
"send_all([EmailNotification(), SMSNotification()], \"System maintenance at 8 PM.\")\n"
],
"id": "7546ba7a"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Practice prompts\n",
"\n",
"1. Create an abstract class called `Shape` with an `area()` method.\n",
"2. Implement `Rectangle` and `Circle`.\n",
"3. Explain how abstraction and polymorphism work together.\n"
],
"id": "dce25926"
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
================================================
FILE: week_x/encapsulation.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Encapsulation\n",
"\n",
"Encapsulation means keeping data and behavior together while controlling how important values can be changed.\n"
],
"id": "5696f6b4"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Learning goals\n",
"\n",
"You will learn to:\n",
"- protect internal state with controlled methods\n",
"- validate changes before storing them\n",
"- connect encapsulation to classes, conditions, and exceptions\n"
],
"id": "46e45f1f"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class Car:\n",
" def __init__(self, speed, color):\n",
" self._speed = speed\n",
" self.color = color\n",
"\n",
" def get_speed(self):\n",
" return self._speed\n",
"\n",
" def set_speed(self, new_speed):\n",
" if new_speed < 0:\n",
" raise ValueError(\"Speed cannot be negative.\")\n",
" self._speed = new_speed\n"
],
"id": "1abeb851"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"car = Car(80, \"blue\")\n",
"print(car.get_speed())\n",
"car.set_speed(95)\n",
"print(car.get_speed())\n"
],
"id": "994a7095"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Validating bad input\n"
],
"id": "a67b16e6"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"try:\n",
" car.set_speed(-10)\n",
"except ValueError as error:\n",
" print(error)\n"
],
"id": "7f480eb0"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Another encapsulation example\n"
],
"id": "4669f809"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class BankAccount:\n",
" def __init__(self, owner, balance):\n",
" self.owner = owner\n",
" self._balance = balance\n",
"\n",
" def get_balance(self):\n",
" return self._balance\n",
"\n",
" def deposit(self, amount):\n",
" if amount <= 0:\n",
" raise ValueError(\"Deposit amount must be positive.\")\n",
" self._balance += amount\n",
"\n",
" def withdraw(self, amount):\n",
" if amount > self._balance:\n",
" raise ValueError(\"Insufficient funds.\")\n",
" self._balance -= amount\n",
"\n",
"account = BankAccount(\"Avery\", 100)\n",
"account.deposit(25)\n",
"account.withdraw(40)\n",
"print(account.get_balance())\n"
],
"id": "9493839b"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Naming convention\n",
"\n",
"A single underscore, like `_balance`, is a Python signal that the attribute is meant for internal use.\n"
],
"id": "0e663e4f"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Practice prompts\n",
"\n",
"1. Add validation for a maximum car speed.\n",
"2. Add error handling when a withdrawal is too large.\n",
"3. Explain why direct unrestricted access can create bugs.\n"
],
"id": "953edf73"
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
================================================
FILE: week_x/polymorphism.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Polymorphism\n",
"\n",
"Polymorphism means different objects can respond to the same method name in their own way.\n"
],
"id": "9a73e89b"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Learning goals\n",
"\n",
"You will learn to:\n",
"- use one shared interface across different classes\n",
"- write flexible functions that accept many object types\n",
"- connect this idea to methods and classes from earlier notebooks\n"
],
"id": "22d82eb0"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class EnglishGreeting:\n",
" def say_hello(self):\n",
" print(\"Hello\")\n",
"\n",
"\n",
"class SpanishGreeting:\n",
" def say_hello(self):\n",
" print(\"Hola\")\n",
"\n",
"\n",
"class JapaneseGreeting:\n",
" def say_hello(self):\n",
" print(\"Konnichiwa\")\n"
],
"id": "4daa844c"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def introduce(greeting_style):\n",
" greeting_style.say_hello()\n",
"\n",
"for greeter in [EnglishGreeting(), SpanishGreeting(), JapaneseGreeting()]:\n",
" introduce(greeter)\n"
],
"id": "6045d114"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Another polymorphism example\n"
],
"id": "f75c1b61"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class Rectangle:\n",
" def area(self, width, height):\n",
" return width * height\n",
"\n",
"\n",
"class Triangle:\n",
" def area(self, width, height):\n",
" return (width * height) / 2\n",
"\n",
"shapes = [Rectangle(), Triangle()]\n",
"for shape in shapes:\n",
" print(shape.area(6, 4))\n"
],
"id": "be244b3d"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Reusing polymorphism with loops\n"
],
"id": "03e7f22e"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class EmailNotifier:\n",
" def send(self, message):\n",
" print(f\"Email: {message}\")\n",
"\n",
"\n",
"class SMSNotifier:\n",
" def send(self, message):\n",
" print(f\"SMS: {message}\")\n",
"\n",
"\n",
"def broadcast(services, message):\n",
" for service in services:\n",
" service.send(message)\n",
"\n",
"broadcast([EmailNotifier(), SMSNotifier()], \"Practice session starts at 4 PM.\")\n"
],
"id": "2c078700"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Practice prompts\n",
"\n",
"1. Create classes with a shared `move()` method.\n",
"2. Write one function that calls `move()` on all of them.\n",
"3. Explain why the function does not need to know every class in advance.\n"
],
"id": "44daa2fb"
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
================================================
FILE: week_x2/0011_practice_unit_testing.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"id": "f8a3746a",
"source": [
"# Week X2 Practice — Unit Testing\n",
"\n",
"This practice notebook is designed to strengthen student thinking, not just student memory. The goal is to turn the week's lesson into repeatable skill.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "3496b160",
"source": [
"## Why this practice notebook matters\n",
"\n",
"In real jobs, developers are expected to do more than remember syntax. They must inspect data carefully, break problems into parts, explain their reasoning, and produce dependable solutions under pressure. These exercises are built to train those habits early.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "5a3e081a",
"source": [
"## Focus areas\n",
"\n",
"- assertions and test cases\n",
"- thinking in edge cases\n",
"- debugging with evidence\n",
"- quality habits used in real teams\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "09b7e921",
"source": [
"## How to use this notebook\n",
"\n",
"1. Solve the warm-up tasks first.\n",
"2. Write your own answer before looking for patterns.\n",
"3. Test small pieces of code often.\n",
"4. Explain *why* your answer works.\n",
"5. Treat the challenge section like exam prep or interview prep.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "3a3c5d1e",
"source": [
"## Warm-up reflection\n",
"\n",
"Before coding, answer these questions in your own words:\n",
"- What is the main idea of this week's topic?\n",
"- What mistakes are beginners likely to make here?\n",
"- How might this topic appear in a real application or workplace task?\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "7034078e",
"execution_count": null,
"outputs": [],
"source": [
"# Warm-up starter for unit testing\n",
"notes = []\n",
"print(\"Use this cell to write quick notes or small experiments about unit testing.\")\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "209bc763",
"source": [
"## Exercise 1 — Read, predict, then run\n",
"\n",
"Read the code first. Predict the output on paper or in your head. Then run it and explain the result.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "a4556e9a",
"execution_count": null,
"outputs": [],
"source": [
"sample_values = [3, 7, 10]\n",
"for value in sample_values:\n",
" print(value * 2)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "80bb8810",
"source": [
"### Your task\n",
"\n",
"Change the values, run the cell again, and explain what changed.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "1b909ccd",
"source": [
"## Exercise 2 — Complete the starter code\n",
"\n",
"Finish the code so that it solves a small realistic problem.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "52079f6c",
"execution_count": null,
"outputs": [],
"source": [
"project_name = \"Starter Project\"\n",
"completed_steps = 2\n",
"total_steps = 5\n",
"\n",
"# TODO: create a message that reports progress clearly.\n",
"# Example idea: \"Starter Project is 40% complete.\"\n",
"\n",
"message = \"Replace this text with your answer.\"\n",
"print(message)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "96d4ea41",
"source": [
"## Exercise 3 — Debugging drill\n",
"\n",
"In real work, you often improve broken code instead of writing from scratch.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "10728bcb",
"execution_count": null,
"outputs": [],
"source": [
"def broken_example(number):\n",
" # TODO: fix the logic so the function returns a useful value.\n",
" result = number + 1\n",
" return result\n",
"\n",
"print(broken_example(5))\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "749bd59a",
"source": [
"### Debugging questions\n",
"\n",
"- What is the code trying to do?\n",
"- Is the variable naming clear enough?\n",
"- How would you test your fix with more than one input?\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "5701af88",
"source": [
"## Exercise 4 — Real-world mini scenario\n",
"\n",
"Imagine you are building a tiny internal tool at work. The code does not need to be huge; it needs to be clear, correct, and easy to maintain.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "75964ec0",
"execution_count": null,
"outputs": [],
"source": [
"items_processed = 14\n",
"items_remaining = 6\n",
"\n",
"# TODO: write logic below that prints a helpful progress update for a teammate.\n",
"print(\"Add your progress update here.\")\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "b7517720",
"source": [
"## Exercise 5 — Explain your reasoning\n",
"\n",
"Write short answers in markdown or comments:\n",
"- Why is your solution readable?\n",
"- How could another developer understand it quickly?\n",
"- What edge case or mistake did you think about?\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "1cd8ad9f",
"source": [
"## Challenge set\n",
"\n",
"Try these without copying from earlier cells:\n",
"1. Solve a small version first.\n",
"2. Generalize your solution.\n",
"3. Test it with at least three different inputs.\n",
"4. Refactor any repeated logic.\n"
]
},
{
"cell_type": "code",
"metadata": {},
"id": "3b13dce9",
"execution_count": null,
"outputs": [],
"source": [
"def challenge_task(data):\n",
" \"\"\"Replace this placeholder with your own solution for the challenge set.\"\"\"\n",
" return data\n",
"\n",
"print(challenge_task(\"start here\"))\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "b5d9d50e",
"source": [
"## Topic-specific challenge ideas for Unit Testing\n",
"\n",
"Use the problems below as exam prep, portfolio prep, or interview-style practice.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "ffd686ce",
"source": [
"1. Write tests for both normal cases and edge cases.\n",
"2. Create a failing test and fix the underlying bug.\n",
"3. Use a loop to run several test cases.\n",
"4. Explain why testing saves time in real engineering work.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "1bb54524",
"source": [
"## Exam-prep mindset\n",
"\n",
"When preparing for major exams or technical interviews, do not just ask, “Can I memorize this?” Ask:\n",
"- Can I explain it clearly?\n",
"- Can I solve a fresh problem with it?\n",
"- Can I debug a broken version of it?\n",
"- Can I choose this approach for the right reason?\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "3bd58e22",
"source": [
"## Career connection\n",
"\n",
"This week's practice is also training real workplace habits: clarity, testing, decomposition, communication, and disciplined thinking. Those habits matter in software engineering, data work, automation, QA, scripting, backend development, and many other roles.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"id": "9e7021c3",
"source": [
"## Self-check before moving on\n",
"\n",
"Rate yourself from 1 to 5 on each question:\n",
"- I can solve a straightforward problem from this topic without copying.\n",
"- I can explain the core idea to another learner.\n",
"- I can debug a small mistake in code from this topic.\n",
"- I can imagine a real-world use case for this topic.\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
================================================
FILE: week_x2/unit_test.ipynb
================================================
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Unit Testing Basics\n",
"\n",
"Testing helps us confirm that our code behaves the way we expect.\n"
],
"id": "5ecae2a3"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Learning goals\n",
"\n",
"You will learn to:\n",
"- write simple assertions\n",
"- test several input cases systematically\n",
"- connect testing to functions from earlier notebooks\n"
],
"id": "5a1cae07"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def add_numbers(a, b):\n",
" \"\"\"Return the sum of two numbers.\"\"\"\n",
" return a + b\n",
"\n",
"print(add_numbers.__doc__)\n",
"print(add_numbers(3, 3))\n"
],
"id": "a78d5822"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## A first manual test\n"
],
"id": "4824c821"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def test_add_numbers():\n",
" assert add_numbers(2, 3) == 5\n",
" assert add_numbers(-1, 1) == 0\n",
" assert add_numbers(0, 0) == 0\n",
"\n",
"\n",
"test_add_numbers()\n",
"print(\"All manual tests passed.\")\n"
],
"id": "5c39ba40"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Several test cases in a loop\n"
],
"id": "616c69c3"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"test_cases = [\n",
" (2, 3, 5),\n",
" (10, -2, 8),\n",
" (3.5, 4.5, 8.0),\n",
"]\n",
"\n",
"for left, right, expected in test_cases:\n",
" result = add_numbers(left, right)\n",
" assert result == expected, f\"Expected {expected}, got {result}\"\n",
"\n",
"print(\"Batch test run completed successfully.\")\n"
],
"id": "9a5230a4"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Testing another function from earlier topics\n"
],
"id": "7ff3ba94"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"source": [
"def is_even(number):\n",
" return number % 2 == 0\n",
"\n",
"assert is_even(0) is True\n",
"assert is_even(8) is True\n",
"assert is_even(7) is False\n",
"print(\"is_even tests passed.\")\n"
],
"id": "f8d0c342"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Why testing matters\n",
"\n",
"Tests turn expectations into executable checks. That is one of the habits that separates guesswork from engineering.\n"
],
"id": "487712f7"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Practice prompts\n",
"\n",
"1. Write tests for `apply_discount`.\n",
"2. Test a function that works with strings.\n",
"3. Add a failing test on purpose and read the error carefully.\n"
],
"id": "6fd19f21"
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}