No history yet

Introduction to Programming

What Is Programming?

Programming is simply the process of giving a computer a set of instructions to follow. Think of it like writing a recipe. A recipe lists ingredients and step-by-step instructions for a chef to follow. If the instructions are clear, you get a delicious cake. If they're confusing or out of order, you might end up with a mess.

A computer can't think for itself. It needs a detailed, precise set of instructions to perform any task, whether it's displaying a website, calculating a sum, or playing a video. A program is that set of instructions, and programming is the act of writing them.

Lesson image

These instructions are written in a special language that both humans can write and computers can understand. This brings us to programming languages.

Talking to Computers

We can't just tell a computer, “Show me a picture of a cat,” in plain English. The computer's native language is binary, a series of ones and zeros, which is incredibly difficult for humans to work with. Programming languages act as a bridge.

There are hundreds of programming languages, each with its own rules, or syntax. Some, like C++, are used for building high-performance applications like video games. Others, like JavaScript, are the backbone of interactive websites. For beginners, a great starting point is Python.

Python is known for its simple and readable syntax. It's designed to let you write programs with fewer lines of code than many other languages.

The rules of a programming language are strict. A misplaced comma or a typo can prevent the entire program from running. This precision is necessary because computers follow instructions literally.

Writing Your First Program

A long-standing tradition for new programmers is to write a program that simply displays the text "Hello, World!" on the screen. It's a simple way to confirm that your setup is working and to see your code in action.

In Python, this is remarkably easy. We use a built-in command called print().

# This is a comment. Python ignores anything after a '#'.
# The print() function displays text to the screen.
print("Hello, World!")

Let's break this down. print is the name of the function, or a pre-written command that performs a specific action. The parentheses () are where we put the information we want the function to work with. In this case, we're giving it the text "Hello, World!". The quotation marks tell Python that this is a piece of text, also known as a string.

When a computer executes this code, it reads the instruction, understands that it needs to use the print function, and displays the string inside the parentheses on the screen.

syntax

noun

The set of rules that defines the combinations of symbols that are considered to be correctly structured statements or expressions in a programming language.

Beyond just printing text, programming is about working with data. To do that, we need a way to store and label information. That's where variables come in.

Storing Information with Variables

A variable is like a labeled box where you can store a piece of information. You give the box a name, and you can put something inside it. Later, you can look inside the box by using its name, or you can change its contents.

In Python, creating a variable is as simple as choosing a name and using the equals sign (=) to assign it a value.

# Create a variable named 'greeting' and store a string in it.
greeting = "Hello again!"

# Create a variable named 'year' and store a number in it.
year = 2024

Here, greeting is a variable holding a string of text, and year is a variable holding a number. Now, instead of typing out the text every time, we can just use the variable's name.

# Use the variable in the print() function.
print(greeting)
print(year)

Executing this code will print "Hello again!" on one line and "2024" on the next. Using variables makes our code more flexible and easier to read. If we wanted to change the greeting, we would only have to change it in one place: where the variable is defined.

Time to review these core concepts.

Now, let's test your knowledge with a few questions.

Quiz Questions 1/6

What is the primary purpose of programming?

Quiz Questions 2/6

Why do we need programming languages instead of just using a human language like English?

Congratulations on taking your first step into programming. You've learned what programming is, how languages like Python help us communicate with computers, and how to write simple instructions to display text and store information.