Back

Section Summary: Programming Basics

divider

Activities 1.1 – 1.9. Use this to review, or to fill in a definition you missed.


1. How a Computer Works

Every computer does four things: takes input, does processing, produces output, and uses memory to hold data along the way. Underneath all of it, data is stored in binary.

Input
Information a computer receives from the outside world.
Output
Information a computer sends back out to the world.
Processing (CPU)
The part of the computer that carries out instructions.
Memory
Where a computer holds data, either temporarily (RAM) or long-term (storage).
Binary
A system of representing information using only two states, on and off.
Bit
A single binary digit, either 0 or 1.
Byte
A group of eight bits.
Programming Language
A structured set of rules for writing instructions a computer can run.
Code Editor
A program built for writing, testing, and running code.

2. Output and Comments

print() displays text in the console. Anything after a # is a comment and is ignored when the program runs.

Function
Code that performs a specific action.
Console Output
Text displayed by a program in a command-line interface, like a terminal.
Comment
A note written within the code that is ignored by Python, used to explain or clarify the code.

3. Variables and Data Types

A variable is a name for a stored value. Every value has a type, and you can check it with type().

Variable
A named location that stores a value for later use.
Assignment
Storing a value in a variable using the = operator.
Data Type
The kind of value a variable holds, such as text or a number.
String (str)
A data type representing text.
Integer (int)
A data type representing a whole number.
Float (float)
A data type representing a decimal number.

4. Arithmetic

Python evaluates expressions using order of operations, and parentheses override it. Beyond the four basic operators there are //, %, and **.

Operator
A symbol that performs an operation, such as + or *.
Operand
A value an operator works on.
Expression
A combination of values and operators that produces a result.
Floor Division
Division that drops any decimal remainder, using //.
Modulus
The remainder left over after division, using %.
Order of Operations
The rules that decide which part of an expression is evaluated first.

5. Changing Values Over Time

A variable can be given a new value at any point, including one calculated from its own current value. What your variables hold at a given moment is the program's state.

Reassignment
Giving an existing variable a new value.
Self-Referential Update
An assignment where a variable's current value is used to compute its new value, like health = health - 20.
State
The current value(s) a program is keeping track of at a given moment.

6. f-Strings

An f-string puts a variable or an expression directly inside a string, instead of joining pieces together by hand.

f-String
A string prefixed with f that can insert variables or expressions directly inside it.
Placeholder
The { } spot inside an f-string where a value gets inserted.
String Interpolation
Inserting a variable's value directly into a string.

7. Input and Type Casting

input() always returns a string, even when the user types digits. To do math with it, cast it first with int() or float().

Console Input
Text a user types into the terminal while a program is running.
input()
A function that displays a message and returns whatever the user types, as a string.
Prompt
The message shown to the user asking for input.
Type Casting
Converting a value from one data type to another.
int()
Converts a value into a whole number.
float()
Converts a value into a decimal number.
Nested Function Call
A function call placed inside another function call, evaluated from the inside out.

8. Modules and Math

Tools that aren't built into Python come from modules you bring in with import. The math module was the first one you used.

Module
A collection of tools not built directly into Python — you bring it in with import.
Constant
A named value, like math.pi, that doesn't change — read directly, not called with ().
round()
Built-in function that rounds a number, optionally to a specific number of decimal places.
math.pow()
Raises a number to a power, same job as **, but always returns a float.
math.sqrt()
Returns the square root of a non-negative number.