Python for Physics Teachers

Session 1: The "Systems Architect" Approach

Objective: Mastering Google Colab and the Logic of Variables.

1. Why Python in the Physics Classroom?

From "Black Box" to "Open Source"

  • The Calculator Problem: Calculations disappear once the "AC" button is pressed.
  • The Script Solution: A script is a visible lesson plan. It shows the logic, the constants, and the relationship between variables.
  • The Architect Role: You don't need to be a programmer. You need to be a Physics Validator who ensures the machine's logic matches physical reality.

2. Meet Your Lab: Google Colab 🚀

No installation required. Just a browser.

  1. Open: colab.research.google.com
  2. Sign in: Use your Google account.
  3. Create: Click "New Notebook."

3. Anatomy of a Notebook

Two types of building blocks:

  1. Text Cells (Markdown): For your lesson titles, instructions, and physics theory.
  2. Code Cells (Python): Where the actual "physics engine" runs.

Try it now: Click + Text and write:
# My First Digital Lab
Then click + Code below it.

4. The Mental Model: "Memory Boxes"

Variables are just labeled containers.

In Physics:
In Python: gravity = 9.8

  • The = is an assignment operator.
  • It means: "Take the value on the right () and store it in the box on the left ()."

5. Your First Physics Script

Copy this into your Code Cell:

# 1. Constants
g = 9.8 

# 2. Inputs
mass = 0.5    # kg
height = 10   # meters

# 3. Physics Logic (The Formula)
potential_energy = mass * g * height

# 4. Output
print(potential_energy)

Click the [▶] Play button to execute.

6. Lab Task 1: The Modification 🛠️

The Goal: See how the "System" reacts to change.

  1. Run the script: Confirm the result is 49.0.

  2. Change the Environment: Change g = 9.8 to g = 1.6 (Moon).

  3. Change the Object: Change mass = 0.5 to mass = 2.5.

  4. Re-run: Notice how the single output line updates based on your new architecture.

7. Lab Task 2: Breaking the Code 🛑

Learning through Error Messages

Computers are literal. If the label doesn't match the box, it fails.

  1. Change the line: potential_energy = mass * g * height

  2. To: potential_energy = weight * g * height

  3. Run it.

  4. Observation: You will see a NameError. Python is telling you: "I don't know what a 'weight' box is. I only know 'mass'."

8. Architecting with LLMs 🤖

How to prompt for Physics Code

Instead of writing code, you instruct the AI using physics parameters.

Prompt Template for Students:

"You are a physics assistant. Write a simple Python script to calculate the speed of a wave on a string.

  1. Create a variable for tension (set to 100).

  2. Create a variable for linear_density (set to 0.01).

  3. Calculate velocity ().

  4. Print the result with the unit 'm/s'."

9. Lab Task 3: The Verification

Validating the Junior Developer (AI)

  1. Paste the AI code into a new Code Cell.

  2. The Architect's Check: * Did the AI use the correct formula?

    • Are the units labeled correctly?
  3. Modify: Change the tension variable to 200. Does the velocity increase as expected?

10. Sharing Your Lesson 📤

How to distribute to your future students

  1. Rename: Click "Untitled.ipynb" Kinematics_Intro.

  2. Share: Click the Share button (top right).

  3. Permissions: Change to "Anyone with the link can view."

  4. Student Action: Tell your students to go to File > Save a copy in Drive.

Summary Checklist ✅

  • [ ] Can you create a Text Cell for instructions?

  • [ ] Can you run a Code Cell using the Play button?

  • [ ] Can you explain what the = sign does?

  • [ ] Can you identify a NameError?

  • [ ] Can you use an LLM to generate a specific formula?

Next Step:

Homework

Create a Colab notebook that calculates Ohm's Law (). Include a Text cell explaining the physics and a Code cell that performs the calculation.

Grading Rubric: Ohm's Law Notebook

Criteria Exceptional (5 pts) Developing (3 pts) Needs Work (1 pt)
Notebook Structure Clear headings and text explanations for every code block. Headings present but sparse explanation. Only code cells; no text context.
Physics Accuracy Correct formula () and appropriate units used. Formula correct but units missing or labeled wrong. Incorrect physics logic.
Variable Naming Descriptive names used (e.g., current, resistance). Generic names used (e.g., x, y). Unclear or confusing names.
Code Execution Script runs without errors on the first try. Script runs after fixing minor syntax typos. Script has fatal logic or NameErrors.

What a "Pass" Looks Like ✅

1. The Text Cell > "In this lab, we calculate the Voltage required to push a current through a resistor."

2. The Code Cell

current = 2.5 # Amperes resistance = 10.0 # Ohms 
voltage = current * resistance 
print("The Required Voltage is:", voltage, "Volts")

Alternatives

  • Coulomb's law
  • Electric potential energy
  • Electric potential
  • Gravitational potential