Part 2: Core Programming Concepts

3. Input & Output

A program as input → process → output

Almost every useful program follows the same shape: it takes some input, processes it according to rules you write, and produces output. This is the IPO model, and keeping it in mind helps you structure any program: ask "what comes in, what must I compute, what goes out?"

INPUT PROCESS OUTPUT keyboard, file, network screen, file, response

Output: showing results

Output is how a program communicates with the outside world. The simplest form is printing text to the screen. Early in your learning, printing is also your most valuable debugging tool: when you are unsure what a variable holds, print it and look.

print("Hello, world!")
name = "Ada"
print("Hello, " + name)      # Hello, Ada
print("Your score is", 95)   # Your score is 95

Input: reading from the user

Input lets the program receive data while it runs, so the same code can work on different values each time. A classic beginner trap: input from the keyboard almost always arrives as a string, even when it looks like a number. If you need to do arithmetic, you must convert (cast) it to the right type first.

name = input("What is your name? ")      # always text
print("Hi " + name)

age_text = input("Your age? ")           # "30" as text
age = int(age_text)                      # convert to integer
print("Next year you will be", age + 1)  # now arithmetic works

If you forget the conversion and try age_text + 1, the program fails because you cannot add a number to text. This single mistake accounts for a large share of early errors, so build the habit of asking "what type is this really?"

Other sources and destinations

The keyboard and screen are only the most visible channels. Input can also come from files, sensors, databases, or network requests; output can go to files, other programs, or back across the network. The IPO shape stays the same — only the channels change. A program that reads a file, transforms its contents and writes a new file is still just input → process → output.

Formatting output

Clear output matters as much as correct computation. Most languages let you build readable messages by inserting values into a template. Rounding a price to two decimals, labelling a number, or lining up columns all make the difference between output a person can use and a wall of raw values.

price = 19.5
print(f"Total: ${price:.2f}")   # Total: $19.50

Key idea: structure programs as input → process → output; always know the type of the data crossing each boundary, and convert at the edges.