Skip to content

Module 1: Python in the Real World

Purpose of this notebook:
Get familiar with what Python is, where it is used, and how simple Python code behaves when you run it.

Run in Binder Open in Colab Download notebook

Read here. Practice in a notebook.

This page shows the original notebook. Open Binder or Colab to run and edit cells. Work one cell at a time: some examples are deliberately broken for debugging practice. Download your work before leaving Binder; its sessions are temporary.

View original source

Learning Outcomes

By the end of this notebook, you should be able to:

  • identify what Python is and where it is used
  • explain basic Python code behavior

Before You Begin

  • Run the notebook from top to bottom
  • Read the code comments
  • Change only the values you are asked to change
  • If something goes wrong, that is okay — mistakes are part of learning

What is Computer Programming?

  • Computer programming is the process of giving clear, step-by-step instructions to a computer so it can perform a task.
  • A program is simply a set of instructions written in a language the computer can understand.

Think About It

Programming is similar to:

  • A recipe → step-by-step instructions to cook a meal
  • A GPS route → directions to reach a destination
  • A checklist → steps to complete a task

In all these cases: * The steps must be clear and in order * Missing or incorrect steps lead to wrong results

Important Idea

Computers do exactly what you tell them to do. * If your instructions are clear → the program works * If your instructions are unclear or incorrect → you get an error or unexpected output This is a normal part of programming.

Why Programming Matters

Programming allows you to: * Automate repetitive tasks * Work with data (e.g., scores, expenses, logs) * Make decisions using logic * Solve simple real-world problems

Quick Example (No Coding Yet)

Task: Calculate the average of 3 numbers

Steps (like a program):

  1. Get the numbers
  2. Add them together
  3. Divide by 3
  4. Show the result

This is exactly how a computer program works—just written in Python.

Reflection

  • Think of a simple task you do daily (e.g., calculating expenses, checking grades, organizing items).
  • What are the step-by-step instructions for that task?

You now understand what programming is: giving step-by-step instructions to a computer.

But how do we actually write these instructions?

👉 We use a programming language.

In this course, we use Python because it is simple, readable, and widely used in real-world applications.

What Is Python?

Python is a programming language used to write instructions (programs) that computers can understand and execute. With Python, you can automate tasks, work with data, and solve real-world problems.

It is a beginner-friendly programming language used to solve practical problems in many fields.

You can find Python in areas such as:

  • IT support and automation
  • business and finance
  • healthcare and health tracking
  • cybersecurity
  • data analysis
  • education

How to Run Code in This Notebook

To run a code cell:

  1. Click inside the cell
  2. Press Shift + Enter

You should see output appear below the cell.

If you see red text, it means there is an error — this is normal in programming.

Demo 1: A Simple Real-World Example

This short program keeps track of support tickets.
Run the code and observe the output.

# Example: counting support tickets

open_tickets = 4
new_tickets = 2
total_tickets = open_tickets + new_tickets

print("Open tickets:", open_tickets)
print("New tickets:", new_tickets)
print("Total tickets to handle:", total_tickets)

Explain the Code

This program does three simple things:

  1. stores values in variables
  2. adds the values together
  3. displays the result with print()

This is one way Python helps people solve practical problems.

Guided Practice

Now try a similar example. Change the values below to match another real-world task, such as:

  • number of assignments to finish
  • number of items in inventory
  • number of patients checked in
  • number of students present
# TODO: Change the numbers to match a different daily task

items_in_stock = 10
new_items = 3
total_items = items_in_stock + new_items

print("Items already in stock:", items_in_stock)
print("New items added:", new_items)
print("Total items now available:", total_items)

Check Your Work

  • Did your total change after you updated the numbers?
  • Does the result make sense?

If yes, your code is working correctly.

Demo 2: Python in Different Fields

Python can support many majors and careers.

Examples: - Business: calculate profit or expenses - Healthcare: track daily steps or health values - Cybersecurity / IT: count login attempts or system alerts - Education: calculate averages or attendance totals

The important idea is this:
Python takes information, processes it, and gives useful output.

Errors Are Normal

In programming, errors happen all the time.

They help you find what needs to be fixed.

👉 When you see an error: - Check spelling - Check quotes (" ") - Check parentheses ( )

You will practice this now.

Debug Challenge

The code below has one small mistake.
Run it, read the error message, fix the code, and run it again.

# This code has a small mistake. Fix it and run it again.

print("Python can be used in many careers!)

Check Your Work

After you fix the error, you should see:

Python can be used in many careers!

If you see that message, you fixed the problem correctly.

Reflection

Answer these questions in a markdown cell below or in your notes:

  1. What is one area where Python can be used?
  2. What did the first program do?
  3. What did you learn from fixing the error?

Final Note

You have now:

  • run Python code
  • observed how code produces output
  • changed values in a program
  • fixed a small error

That is a strong start. You are ready for the next notebook.