Mascot image.
#EECS#Python#Intro

What are we actually doing when we program?

A program is just a precise list of instructions that transforms input into output.

That sounds small, but it already contains most of the course:

  • we need data,
  • we need rules for transforming that data,
  • and we need a way to reason about whether the rules do what we claim.

In Python, the smallest examples already show the whole picture.

name = input("Name: ")
print(f"hello, {name}")

This has an input channel, a stored variable, and an output rule. Nothing magical happened. The machine just followed instructions exactly.

Variables and expressions

Think of a variable as a name bound to a value.

x = 7
y = 2 * x + 5

Now x stores 7, and y stores 19.

Mathematically, this is close to substitution, but not identical. In algebra, x = 7 describes equality. In Python, x = 7 is assignment: take the object 7 and bind the name x to it.

That distinction matters.

x = 7
x = x + 1

This is nonsense as an equation in pure math, but perfectly valid as a program. The second line means: read the old value of x, add 1, then store the new result back into x.

First mental model

The machine is brutally literal.

If you want a good programming habit early, read each line and ask:

  1. What values exist right now?
  2. What operation is this line performing?
  3. What new state exists after this line executes?

That habit prevents a lot of fake understanding.

A first function

Functions let us package repeated logic into a reusable rule.

def square(n: float) -> float:
    return n * n

Mathematically, this is the rule

f(n)=n2.f(n) = n^2.

In code, the same idea becomes a named block that can be executed on demand.

print(square(3))
print(square(1.5))

The point is not just convenience. A function forces us to isolate the input, isolate the output, and separate the rule from the rest of the program.

Worked example: Celsius to Fahrenheit

The conversion formula is

F=95C+32.F = \frac{9}{5}C + 32.

That becomes:

def c_to_f(celsius: float) -> float:
    return (9 / 5) * celsius + 32

This is the kind of bridge I want this course to keep making:

  • mathematics gives the structure,
  • code makes the structure executable.

Recitation-style checks

Try these before looking anywhere else:

  1. Write a function cube(n) that returns n3n^3.
  2. Ask the user for two numbers and print their average.
  3. Explain, in words, why x = x + 1 is legal in Python but not a true algebraic identity.

A small debugging note

Most beginner bugs are not deep.

They usually come from one of four things:

  • wrong indentation,
  • misspelled names,
  • mixing strings and numbers,
  • misunderstanding the order in which lines execute.

That is good news. It means debugging is often just careful reading.