๐Ÿ“ What is a Python Program?

A Python program is a list of instructions that runs top-to-bottom. Every line tells Python what to do โ€” print text, ask for input, or calculate a result.

# Your first program
print("Hello, World!")

In plain English: write commands in a .py file, save it, and run it from your terminal.

By the end of this lesson, you'll write a personalized greeting program that asks someone's name and responds with a custom welcome โ€” the exact way every coder starts.

โšก Core Concepts for Your First Program

print()
print("Hi")
Output text to the screen.
input()
input("Name?")
Ask the user for text.
String format
f"Hi {name}"
Embed variables in text.
Comments
# This is a comment
Notes that Python ignores.
SyntaxError
print("Hi"
Missing bracket โ€” program won't run.
Indentation
print()
Python counts spaces โ€” they matter.

๐Ÿš€ The Beginner's Scenario

๐Ÿ‘ฉโ€๐Ÿ’ป
First-Time Coder ยท Aisha in Nairobi
Writing a Welcome Program for Coding Class

Aisha just installed Python and VS Code in Nairobi. For her first coding assignment, she needs to write a program that greets her classmates by name. She'll start with print() to say hello, then use input() to ask for a name, and finally combine them with string formatting to create a personalized greeting โ€” all in one .py file, run from the terminal.

3
Core functions
~20
Lines of code
<1min
To complete

๐Ÿ’ป Step 1: Your First print()

hello.py โ–ถ Run to see output below
# Output Hello, World! Welcome to Ramayai AI Academy I just wrote my first Python program!

๐ŸŽค Step 2: Ask for Input with input()

Now Aisha wants to ask her classmates for their names. She uses input() to pause the program, display a prompt, and capture what the user types.

greet_with_name.py โ–ถ Run and type a name
# Example Output (if user enters "Aisha") What is your name? Aisha Hello, Aisha Nice to meet you!

โœจ Step 3: String Formatting with f-strings

Instead of using + to join strings, Python has a cleaner way: f-strings. Put an f before the quote and wrap variables in {}.

personalized_greeting.py โ–ถ Run and type a name
# Example Output (if user enters "Aisha" and "18") What is your name? Aisha How old are you? 18 Hello, Aisha! You are 18 years old. Great to have you at Ramayai AI Academy, Aisha! In -14 years, you'll be a pro!

โš ๏ธ Step 4: Common Errors and How to Fix Them

Every programmer writes programs with errors. The key is learning to read the error message and fix it.

errors_demo.py โ–ถ Examples of what NOT to do
# Output This program runs fine! Hello, Arjun!

๐ŸŒ Where You'll Use These Skills

Also used in

๐Ÿค–
AI & Machine Learning
Every ML model learns from data read via input(), processed, then output with print().
๐Ÿ’ฌ
Chatbots & Conversational AI
Chatbots ask questions with input(), process the response, and reply with print(). You're building the prototype.
๐Ÿ“Š
Data Science & Analytics
Data pipelines read CSV files (like input), transform the data, and export results (like print). This is your foundation.

๐Ÿค– How This Connects to AI

Every time an AI model takes user input (like ChatGPT listening to you), processes it, and generates output (like "Hello, here's my response"), it's using the same input() โ†’ process โ†’ print() pattern you just learned. You're not learning syntax for syntax's sake โ€” you're learning the core loop of every AI interaction.

input() = user query process = model inference print() = AI response

๐ŸŽฏ Mini Challenge

Write a Coffee Order Program

Create a program called coffee_order.py that:

  • Asks "What is your name?" and stores it
  • Asks "What size coffee? (S/M/L)" and stores it
  • Uses an f-string to print: "One {size} coffee for {name}. That'll be ready in 5 minutes!"

Bonus: If they choose "L", add a 30% upcharge message.

size = input("What size coffee? (S/M/L) ")
Then use if size == "L": print("That's +30% โ€” โ‚น45 extra!")

๐Ÿ’ผ Interview Questions

Easy

print() returns None. It doesn't give you back a value โ€” it just sends text to the screen. If you try to store it: x = print("hi"), then x will be None, not the string "hi".

Easy

In Python 3 (which you're using), there is only input(). In Python 2, raw_input() read text and input() tried to evaluate it as code โ€” a dangerous design. Python 3 merged them: input() always returns a string. If you need a number, cast it: int(input()).

Medium

Python uses indentation to mark code blocks โ€” for loops, if statements, functions. Instead of curly braces like {} in Java or C, Python uses spaces. It forces readable code. If you have extra spaces where they don't belong, Python raises IndentationError. This is intentional and makes Python code cleaner to read.

Medium

Python raises a ValueError: invalid literal for int() with base 10: 'hello'. Your program crashes. To handle this safely, you need try/except blocks (covered in Lesson 10). For now, just document that your program expects a number.

Hard

f-strings are faster, more readable, and handle type conversion automatically. f"Age: {age}" works even if age is an integer. With +, you'd need "Age: " + str(age) โ€” more typing and slower. f-strings also let you format numbers: f"{price:.2f}" rounds to 2 decimals. In large data pipelines, this efficiency matters.

๐ŸŽ“ Quick Quiz

Question 1 of 5
Which line prints "Hello" to the screen?
Question 2 of 5
What does name = input("Name: ") do?
Question 3 of 5
What will this code print? name = "Arjun"; print(f"Hi {name}")
Question 4 of 5
What error does this code have? print("Hello"
Question 5 of 5
Which is the correct way to combine a string and an integer in Python 3?
0
/5

๐Ÿ“‹ Quick Cheatsheet

TaskSyntaxExample
Print textprint()print("Hello")
Ask for inputinput()name = input("Name: ")
Join strings+"Hi " + name
Format stringsf"..."f"Hi {name}, you are {age}"
Comment## This is a comment
Convert to intint()int(input())

โš ๏ธ Common Mistakes

Forgetting parentheses in print()
Wrong: print "Hello" (Python 2 syntax). Right: print("Hello"). In Python 3, print is a function and needs parentheses.
Trying to add a string and a number with +
Wrong: "Age: " + 25. Right: f"Age: {25}" or "Age: " + str(25). f-strings are cleaner and always work.
Using input() without storing the result
Wrong: input("Name: ") alone โ€” the input disappears. Right: name = input("Name: ") โ€” store it in a variable so you can use it later.
Adding extra spaces for indentation by accident
Python counts every space. If you mix tabs and spaces, Python will raise IndentationError. Always use spaces (or always use tabs, but spaces are standard). In VS Code, use the space key, not Tab.

โœฆ Key Takeaways

  • print() outputs text to the screen; it returns None
  • input() pauses your program, asks the user for text, and returns what they type (always as a string)
  • Use f-strings (f"text {variable}") to embed variables in text โ€” cleaner than + concatenation
  • Comments start with # โ€” Python ignores them, they're for you
  • SyntaxError = broken grammar (missing parenthesis). IndentationError = wrong spaces. NameError = variable doesn't exist
  • Save your program as filename.py and run it: python filename.py in the terminal
Africa & India's Best AI Academy
๐Ÿค– AI-first ๐ŸŽ“ Placement Assistance

You've written your first program.
Now scale it with industry experts.

Join the Best AI Program: The AI-Era Analyst โ€” 5 months, fully online, with placement assistance. Week 1 is free.

Explore The AI-Era Analyst โ†’