Skip to content
UnderDunn Courses

What Is a Program?

Programming FoundationsLesson 1 of 835 minutesLab included

A program is a set of instructions written to make a computer perform some task. That task might be adding two numbers, displaying a website, decoding a photograph, or keeping an alarming number of browser tabs alive.

The instructions usually begin as source code: text written in a programming language. A programming language gives us a defined vocabulary and grammar for expressing operations. The grammar matters because the computer cannot politely infer what we probably meant.

Consider this tiny Python program:

name = "Ada"
message = "Hello, " + name
print(message)

Even before learning Python, we can make a reasonable first pass:

  1. Store the text Ada under the name name.
  2. Combine Hello, with the stored name and call the result message.
  3. Display the message.

The source code is not the running program. It is a durable description of what should happen. When the program runs, the computer creates a process that carries out those instructions. You encountered processes in Linux Foundations; now we care about what one is doing internally.

When you meet a small program, begin with four questions:

  1. What input can enter?
  2. What operations are performed?
  3. What state changes while it runs?
  4. What output or effect does it produce?

Input is data received by the program. It may come from the keyboard, a command-line argument, a file, a network connection, or another program.

An operation is work performed on that data: adding numbers, comparing text, copying bytes, or choosing which instruction comes next.

State is information the program currently remembers. In the example, name and message are pieces of state. State can change as instructions run.

Output is what leaves the program or changes outside it. Printed text is output, but so is a written file, a network message, or an exit status returned to the shell.

These categories are not merely vocabulary for a quiz. Vulnerability research often begins by asking whether unusual input can drive state and operations toward an output the author did not intend.

Knowledge check

Question 1 of 2

Which statement best distinguishes source code from a process?

A processor does not directly execute Python or C source code as written. Something must bridge the gap between the language humans work with and instructions the machine can execute.

An interpreter reads a program and carries out its meaning. Python is normally introduced this way: the python3 program reads your Python source and executes it.

A compiler translates source code into another form before you run it. A C compiler can turn C source into a native executable containing machine instructions for a particular platform.

That distinction is useful, but reality has more machinery underneath it. Python first converts source into an intermediate bytecode, and modern compilers perform several stages of processing before producing an executable. We will inspect those details when they help answer a real question. For now, remember the practical difference:

  • With our Python examples, we give the source file to python3 when we want it to run.
  • With our C examples, we compile the source into an executable and then run that executable.

Neither approach makes one language a toy and the other a “real” language. They expose different parts of the system, which is why we will use both.

Open a terminal in your Linux course VM. First, confirm that Python 3 is available:

Terminal window
python3 --version

You should see output beginning with Python 3. The remaining version numbers may differ from the example used to write this course, and that is fine.

If the terminal reports something similar to:

python3: command not found

then Python 3 is not currently available through the normal command path. On the Ubuntu course VM, install it with Ubuntu’s package manager.

First, refresh the package list:

Terminal window
sudo apt update

sudo asks Linux to run this administrative command with elevated privileges. Enter the password for your course VM when prompted. The terminal will not display dots or asterisks while you type the password; it is still accepting the keystrokes.

After the package list finishes updating, install Python 3:

Terminal window
sudo apt install python3

When apt asks whether you want to continue, review the proposed change, type y, and press Enter. Then verify the result:

Terminal window
python3 --version

Do not substitute python if that command is missing. Some Linux systems do not create a python command, and others may configure it differently. This course uses python3 explicitly so there is no mystery about which major version we intend to run.

Create a directory for this module:

Terminal window
mkdir -p ~/underdunn-course/programming-foundations
cd ~/underdunn-course/programming-foundations
pwd

The final pwd output should end with:

/underdunn-course/programming-foundations

Open the Text Editor application. Enter these three lines exactly:

name = "Ada"
message = "Hello, " + name
print(message)

Save the file as hello.py in Home/underdunn-course/programming-foundations.

Return to the terminal and confirm the file is where you expect it:

Terminal window
ls -l hello.py
file hello.py

file should identify it as text. That tells us about the stored source file, not what the instructions will do.

Run the program:

Terminal window
python3 hello.py

The output should be:

Hello, Ada

Compare that observation with your prediction. The first line created state named name. The second line read that state, performed a text-combination operation, and created new state named message. The third line produced output.

The quotation marks do not appear because they mark text in the source code; they are not part of the text between them.

Edit hello.py and replace Ada with your name. Before running it, predict exactly which part of the output will change and which parts will stay the same.

Run it again:

Terminal window
python3 hello.py

You changed one input value embedded in the source while leaving the operations alone. If several lines changed unexpectedly, recheck the file rather than adding more changes. Controlled experiments are much easier to reason about than a pile of simultaneous edits.

Now add a second print instruction:

name = "your name"
message = "Hello, " + name
print(message)
print("The program reached the end.")

Predict the order of the two lines, then run the program. Python normally carries out these instructions from top to bottom. Later, conditions, loops, and functions will make the path less direct.

Temporarily remove the closing quotation mark from the first line:

name = "Ada

Run the program again. Python should report a SyntaxError and point near the place where it could no longer understand the source.

A syntax error means the source does not follow the language’s grammar, so Python cannot begin carrying out the program. The error message is evidence: it identifies the type of failure, the file, a line, and often the part that first became impossible to parse.

Repair the quotation mark and run the program once more. Do not leave the exercise in a broken state simply because the broken state was educational.

Add a short entry to your research notebook:

Question Observation
What was the source file? The absolute path to hello.py
What ran the source? The command you used
What state did the program create? The names and values you observed in the code
What output did it produce? The exact terminal output
What happened after the syntax was broken? The error type and referenced line

This may feel excessive for three lines of Python. The program is deliberately simple so we can practice the method without drowning in code. Later, the same record will keep an unfamiliar program from turning into a vague memory of commands you tried.

Knowledge check

Question 1 of 3

What role does python3 play when you run python3 hello.py?

You can now separate the file containing source code from the process created when that code runs. You also have a first-pass method for reading a program: identify its input, operations, state, and output; predict behavior; run it; and compare the evidence with the prediction.

Next, Python Scripts and Values will replace the fixed name with data supplied when the program runs. That is where programs become more useful—and where the input begins to deserve suspicion.