๐ 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.
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
๐ The Beginner's Scenario
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.
๐ป Step 1: Your First print()
๐ค 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.
โจ 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 {}.
โ ๏ธ 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.
๐ Where You'll Use These Skills
Also used in
input(), processed, then output with print().input(), process the response, and reply with print(). You're building the prototype.๐ค 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.
๐ฏ Mini Challenge
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
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".
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()).
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.
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.
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
name = input("Name: ") do?name = "Arjun"; print(f"Hi {name}")print("Hello"๐ Quick Cheatsheet
| Task | Syntax | Example |
|---|---|---|
| Print text | print() | print("Hello") |
| Ask for input | input() | name = input("Name: ") |
| Join strings | + | "Hi " + name |
| Format strings | f"..." | f"Hi {name}, you are {age}" |
| Comment | # | # This is a comment |
| Convert to int | int() | int(input()) |
โ ๏ธ Common Mistakes
print()print "Hello" (Python 2 syntax). Right: print("Hello"). In Python 3, print is a function and needs parentheses.+"Age: " + 25. Right: f"Age: {25}" or "Age: " + str(25). f-strings are cleaner and always work.input() without storing the resultinput("Name: ") alone โ the input disappears. Right: name = input("Name: ") โ store it in a variable so you can use it later.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 returnsNoneinput()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.pyand run it:python filename.pyin the terminal
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 โ