Welcome to Your First Steps in Programming!

Hello, future AI explorer! You’ve done an amazing job so far, understanding what AI and Machine Learning are all about, why they’re so powerful, and how they learn from data. That’s a huge achievement, and you should be really proud!

Today, we’re going to take a super exciting step: learning how to talk to computers. Think of it like learning a new language. Just as you speak English (or another human language) to communicate with people, we use a special language called “programming” to give instructions to computers. This is how we’ll eventually tell our AI models what to do, what data to look at, and what predictions to make.

Don’t worry, we’re starting incredibly small, one tiny step at a time. Programming might sound intimidating, but I promise it’s just about being clear and logical, like writing a recipe. By the end of this chapter, you’ll have written your very first lines of code and seen a computer follow your instructions! How cool is that?

What is Programming? Your Computer’s Recipe Book

Imagine you have a very enthusiastic but extremely literal assistant in the kitchen. This assistant can do anything you ask, but only if your instructions are perfectly clear, step-by-step, and in a language they understand. You can’t just say, “Make dinner!” You have to say:

  1. “Take out the pasta box.”
  2. “Fill a pot with water.”
  3. “Place the pot on the stove.”
  4. “Turn the stove to high heat.”
  5. “Wait for the water to boil.”
  6. “Add pasta to the boiling water.”

This step-by-step list is exactly what programming is! We write a “recipe” – a set of detailed instructions – for the computer. This recipe is called a program, and the act of writing it is programming or coding.

Computers don’t understand human languages directly, so we use special programming languages. For AI and Machine Learning, one of the most popular and beginner-friendly languages is Python. It’s known for being easy to read, almost like plain English, which makes it perfect for us to start with!

Why Does This Matter for AI?

Remember how we talked about AI models “learning” from data? Well, someone has to tell the computer how to learn. Someone has to tell it:

  • “Go get this specific data.”
  • “Look for patterns in this way.”
  • “If you see this, predict that.”
  • “Tell me your prediction.”

All these instructions are given through programming! So, while we won’t build a full AI today, we’re learning the fundamental language to communicate with it.

Your First Example: Making the Computer “Speak”

Let’s jump right in! Our very first instruction to the computer will be to make it say something. In Python, there’s a special instruction for this called print().

Here’s what it looks like:

print("Hello, friend!")

Now, let’s break down what’s happening here, line by line:

print("Hello, friend!")
  • print: This is a special keyword in Python that tells the computer, “Hey, I want you to display something on the screen!”
  • ( and ): These are parentheses. They act like a container for whatever information we want the print instruction to work with. In this case, we’re putting the message we want to display inside them.
  • "Hello, friend!": This is the actual message we want the computer to show. When you see text wrapped in quotation marks (" or '), it’s called a string in programming. It just means “plain text.”

When the computer sees this line of code, it will simply display:

Hello, friend!

Pretty cool, right? You just gave your first instruction!

Setting Up Your Coding “Kitchen” (Google Colab)

Before we write more code, we need a place to write and run it. Think of it as your digital kitchen where you’ll create your Python recipes. The best tool for absolute beginners, especially for AI, is Google Colab. It’s completely free, runs in your web browser, and requires zero installation!

Here’s how to get started with Google Colab (as of January 2026):

  1. Open your web browser (like Chrome, Firefox, Safari).

  2. Go to Google Colab: Type colab.research.google.com into the address bar and press Enter.

  3. Sign in with your Google Account: If you’re not already signed in, Colab will ask you to sign in with any Google account (like your Gmail account).

  4. Create a New Notebook:

    • Once you’re on the Colab welcome screen, look for a button that says “New notebook” or “File > New notebook” in the top menu. Click it!
    • This will open a fresh, empty page. This page is called a “notebook,” and it’s where we’ll write our code.
  5. You’ll see a “code cell”: It’s a gray box with a play button (▶) next to it. This is where you type your Python instructions.

    +----------------------+
    | ▶                    |  <-- This is a code cell
    |                      |
    | In [ ]:              |
    |                      |
    +----------------------+
    
  6. Type your code: In that gray box, type print("Hello, friend!") exactly as you saw it.

  7. Run your code: Click the little play button (▶) next to the code cell, or press Shift + Enter on your keyboard.

    • The first time you run a cell in a new notebook, it might take a moment to “connect” to Google’s computers. You’ll see “Connecting…” or “Initializing…”
    • Once it’s connected, you’ll see the output right below your code cell!
    print("Hello, friend!")
    
    Hello, friend!
    

Great job! You just ran your first piece of code in a professional environment!

Core Concept: Variables - Your Labeled Storage Boxes

Imagine you’re packing for a trip, and you have a bunch of items. Instead of just throwing everything into one big bag, you use smaller, labeled boxes: one for “Socks,” one for “Shirts,” one for “Toiletries.” This makes things organized and easy to find.

In programming, we often need to store pieces of information – like a person’s name, their age, a number, or a message. We use variables for this.

A variable is like a labeled box in your computer’s memory that can hold a value. You give the box a name, and you put something inside it.

Here’s how we create variables in Python:

my_name = "Alice"
my_age = 30

Let’s break it down:

  • my_name: This is the name of our variable (our label for the box). You get to choose meaningful names!
  • =: This is the assignment operator. It means “store the value on the right side into the variable on the left side.”
  • "Alice": This is the value we’re storing. In this case, it’s the text “Alice”.
  • my_age = 30: Here, we’re creating another variable called my_age and storing the number 30 in it.

Now, once you’ve stored values in variables, you can use those variables in your print() statements!

my_name = "Alice"
my_age = 30

print(my_name)
print(my_age)
print("My name is", my_name, "and I am", my_age, "years old.")

If you run this in Colab, you’ll see:

Alice
30
My name is Alice and I am 30 years old.

Notice how my_name and my_age are not in quotation marks when we use them in print(). That’s because we want Python to look inside the “box” and use the value stored there, not print the words “my_name” or “my_age” literally.

Visualizing Variables

Think of it like this in your computer’s memory:

+----------------+
|  my_name       |  <-- Label on the box
+----------------+
| "Alice"        |  <-- What's inside the box
+----------------+

+----------------+
|  my_age        |
+----------------+
| 30             |
+----------------+

Why Variables are Important for AI:

AI models deal with tons of information! Variables are used to store:

  • Pieces of data (like the color of a pixel, a word in a sentence, a person’s height).
  • Results of calculations (like how “sure” the AI is about a prediction).
  • Settings for the AI model (like how fast it should learn).

They are fundamental for managing information.

Core Concept: Basic Math Operations

Computers are incredibly good at math! They can do calculations much faster and more accurately than humans. Python makes it super easy to perform basic arithmetic.

Here are the main math operators:

  • + (addition)
  • - (subtraction)
  • * (multiplication)
  • / (division)

Let’s see them in action:

result_add = 5 + 3
result_subtract = 10 - 4
result_multiply = 6 * 7
result_divide = 20 / 5

print("5 + 3 =", result_add)
print("10 - 4 =", result_subtract)
print("6 * 7 =", result_multiply)
print("20 / 5 =", result_divide)

Output:

5 + 3 = 8
10 - 4 = 6
6 * 7 = 42
20 / 5 = 4.0

Notice that division (/) often gives you a number with a decimal point, even if it’s a whole number (like 4.0 instead of 4). This is normal!

You can also use variables in your calculations:

apples = 10
eaten = 3
remaining_apples = apples - eaten

print("I started with", apples, "apples.")
print("I ate", eaten, "apples.")
print("Now I have", remaining_apples, "apples left.")

Output:

I started with 10 apples.
I ate 3 apples.
Now I have 7 apples left.

Why Math is Important for AI:

Every single “learning” step an AI model takes involves a massive amount of math!

  • When an AI adjusts its “understanding” based on new data, it’s doing calculations.
  • When it makes a prediction, it’s performing mathematical operations on the input data.
  • Even understanding images or language involves converting them into numbers and doing math.

So, while we’re starting with simple sums, these are the tiny building blocks of complex AI.

Step-by-Step Tutorial: Your Personalized Greeting Program!

Let’s combine what we’ve learned to build a small, interactive program! We’ll make a program that asks for your name and then greets you personally.

Goal: Ask for the user’s name, store it, and then say “Hello, [Name]!”

Open a new code cell in Google Colab (or clear the previous one).

Step 1: Ask for input We know how to print() messages. Let’s start by asking the user for their name.

print("What's your name?")

Run this cell. You’ll see “What’s your name?” printed. That’s a good start!

Step 2: Get user input Now, we need a way for the computer to listen to what the user types. For this, Python has the input() instruction. Whatever the user types will be captured by input().

print("What's your name?")
input() # This will wait for you to type something and press Enter

Run this cell. You’ll see “What’s your name?” and then a small text box will appear below it. Type your name, then press Enter. Nothing else happens yet, but the computer did receive your input!

Step 3: Store the input in a variable That input() instruction is great, but we want to remember what the user typed. This is where our “labeled boxes” (variables) come in! We’ll store whatever input() gets into a variable.

print("What's your name?")
user_name = input() # The text you type will be stored in 'user_name'
print("You typed:", user_name) # Let's print it to see!

Run this cell. Type your name, press Enter. Now you’ll see “You typed: [Your Name]”. Awesome! You’ve successfully captured information from the user!

Step 4: Create a personalized greeting Finally, let’s use the stored name to give a warm, personalized greeting. We can combine text and variables in print() in a few ways. One very common and easy-to-read way is using an f-string. You put an f before the opening quote, and then you can put variable names directly inside curly braces {} within your text.

print("What's your name?")
user_name = input()
print(f"Hello, {user_name}! It's great to meet you!")

Run this cell. Type your name, press Enter. You should now see a friendly, customized greeting!

What's your name?
[Type your name here, e.g., Sarah]
Hello, Sarah! It's great to meet you!

You just built your first interactive program! You told the computer to ask a question, listen for an answer, remember it, and then use that remembered information to respond. That’s real programming!

Common Mistakes (And How to Fix Them!)

Don’t worry if your code didn’t work perfectly the first time. Even experienced programmers make mistakes (we call them “bugs”!). It’s totally normal, and learning to fix them is a huge part of becoming a programmer.

Here are some common beginner mistakes:

  1. Typos (Spelling Errors):

    • Mistake: Typing prnt("Hello") instead of print("Hello").
    • What happens: Python will give you an NameError, saying name 'prnt' is not defined. It means “I don’t know what prnt means!”
    • Fix: Double-check your spelling! Python is very picky.
  2. Missing Parentheses () or Quotation Marks "":

    • Mistake: print("Hello" or print(Hello)
    • What happens: Python will give you a SyntaxError (meaning “your grammar is wrong”) or NameError if you forget quotes around text.
    • Fix: Always make sure every opening parenthesis ( has a closing ) and every opening quote " has a closing "!
  3. Case Sensitivity:

    • Mistake: Typing Print("Hello") instead of print("Hello").
    • What happens: Python will give a NameError, because Print (with a capital P) is different from print (with a lowercase p).
    • Fix: Python is case-sensitive! my_name is different from My_Name. Stick to lowercase for built-in commands like print and input.
  4. Forgetting to Run a Cell (in Colab):

    • Mistake: You type new code, but the output doesn’t change, or a variable seems “unknown.”
    • What happens: If you define my_name = "Alice" in one cell, but then try to print(my_name) in a different cell without running the first one, Python won’t know what my_name is yet.
    • Fix: Always run your cells in order, especially if one cell defines variables that another cell uses. The play button (▶) is your friend!

Remember, debugging (finding and fixing errors) is a skill, and you’re building it right now! Every error is an opportunity to learn.

Practice Time! 🎯

You’ve learned a lot of fundamental concepts. Now it’s time to put them into practice! Use your Google Colab notebook for these exercises. Create a new code cell for each one.


Exercise 1: Say Hi to the World! (Easy)

Your task is to simply make the computer print the message: “Hi, AI Learner!”

  • Hint: Remember the first instruction we learned to make the computer display text.
  • Expected Output:
    Hi, AI Learner!
    

Exercise 2: Your Super Simple Calculator (Medium)

Let’s make a mini-calculator! Create two variables, num1 and num2, and assign them any numbers you like (e.g., num1 = 15, num2 = 7). Then, calculate their sum and print the result.

  • Hint: Use the + operator and store the sum in a new variable.
  • Expected Output (if num1=15, num2=7):
    The sum is: 22
    
    (Your numbers and sum will be different depending on what you chose!)

Exercise 3: Your Favorite Animal Story (Challenge)

This one combines input(), variables, and print()!

  1. Ask the user: “What is your favorite animal?” Store their answer in a variable called fav_animal.
  2. Ask the user: “How many of them would you like to have?” Store their answer in a variable called animal_count.
  3. Then, print a fun sentence using both pieces of information!
  • Hint: Use an f-string to combine the text and your variables in the final print() statement.
  • Expected Output (example):
    What is your favorite animal?
    [User types: dog]
    How many of them would you like to have?
    [User types: 3]
    Wow! You want 3 dogs! That's a lot of fun!
    
    (Your output will depend on what the user types!)

Solutions (Don’t peek until you’ve tried!)


Solution 1: Say Hi to the World!

print("Hi, AI Learner!")

Explanation: This simply uses the print() function to display the specified text.


Solution 2: Your Super Simple Calculator

num1 = 15
num2 = 7
sum_result = num1 + num2
print(f"The sum is: {sum_result}")

Explanation:

  1. We create num1 and num2 to hold our numbers.
  2. We calculate their sum using + and store it in sum_result.
  3. Finally, we use an f-string in print() to show the result clearly.

Solution 3: Your Favorite Animal Story

print("What is your favorite animal?")
fav_animal = input()

print("How many of them would you like to have?")
animal_count = input()

print(f"Wow! You want {animal_count} {fav_animal}s! That's a lot of fun!")

Explanation:

  1. We prompt the user for their favorite animal and store it in fav_animal.
  2. We prompt for the count and store it in animal_count.
  3. The final print() uses an f-string to smoothly embed the animal_count and fav_animal into a sentence, making it personalized. Notice the s after {fav_animal} to make it plural – a small touch for better English!

Quick Recap

You’ve done an incredible amount of learning today! Let’s quickly review what you’ve mastered:

  • What Programming Is: Giving precise, step-by-step instructions (a “recipe”) to a computer.
  • Python: Our beginner-friendly programming language.
  • Google Colab: Your free, easy-to-use “coding kitchen” in the browser.
  • print(): The instruction to make the computer display text on the screen.
  • input(): The instruction to make the computer listen and capture text from the user.
  • Variables: Labeled “storage boxes” in the computer’s memory to hold information (like my_name = "Alice").
  • Basic Math: How to perform addition, subtraction, multiplication, and division.
  • Common Mistakes: You learned about typos, missing symbols, and case sensitivity – and that it’s okay to make them!

You’re not just reading about AI anymore; you’re starting to learn how to command it! You’re building a fantastic foundation. Great job!

What’s Next?

In our next chapter, we’ll continue building on these fundamental programming skills. We’ll explore how computers can make decisions (like “if it’s raining, take an umbrella”) and perform repeated tasks (like “do this 10 times”). These concepts are absolutely crucial for AI, as they allow models to process large amounts of data and follow complex learning rules.

Keep up the curiosity and that awesome learning spirit! You’re doing awesome.