A tip calculator (takes a bill amount, calculates tip at different percentages) and a password generator (creates random strong passwords of a specified length). Both run in your terminal by the end of this lesson.
Installing Python
Go to python.org/downloads and download Python 3.11 or newer. Run the installer. On Windows, check "Add Python to PATH" before clicking Install.
Once installed, open a terminal (Terminal on Mac, Command Prompt or PowerShell on Windows) and run:
$ python --version
You should see Python 3.11.x or similar. If you get an error, try python3 --version — on Mac, that's often the right command.
One more thing: Install VS Code from code.visualstudio.com. It's free, and it's what every professional Python developer uses. Install the Python extension once it's open.
Variables and Data Types
A variable is a name that holds a value. Python has four basic types you'll use constantly:
# String — text, wrapped in quotes
name = "Claude"
message = "Analyze this document"
# Integer — whole numbers
max_tokens = 1024
num_files = 47
# Float — decimal numbers
temperature = 0.7
bill_amount = 84.50
# Boolean — True or False
is_complete = True
has_error = False
# Print any variable
print(name) # Claude
print(max_tokens) # 1024
Variable names are lowercase with underscores (max_tokens, not MaxTokens). This convention is called snake_case and it's what all Python code uses.
if/else, for loops, while loops
These three control structures handle 90% of all decision-making and repetition in Python programs.
if/else
api_response = "success"
tokens_used = 850
if api_response == "success":
print("Got a response!")
elif api_response == "error":
print("Something went wrong")
else:
print("Unknown status")
# Comparison operators
if tokens_used > 1000:
print("Warning: high token usage")
else:
print(f"Used {tokens_used} tokens — within budget")
for loops
documents = ["report.pdf", "notes.txt", "data.csv"]
for doc in documents:
print(f"Processing: {doc}")
# range() generates numbers
for i in range(5):
print(f"Step {i}") # 0, 1, 2, 3, 4
Why this matters for AI: In Day 5, you'll use a for loop to process every file in a folder — iterating over documents exactly like this, sending each one to Claude.
Writing Reusable Code
A function is a reusable block of code. Define it once, call it anywhere. Every AI program you write will be organized into functions.
def calculate_tip(bill, tip_percent):
"""Calculate the tip amount and total."""
tip = bill * (tip_percent / 100)
total = bill + tip
return tip, total
# Call the function
tip, total = calculate_tip(84.50, 20)
print(f"Tip: ${tip:.2f}") # Tip: $16.90
print(f"Total: ${total:.2f}") # Total: $101.40
# Functions with default values
def build_prompt(task, tone="professional"):
return f"Please {task}. Tone: {tone}."
print(build_prompt("summarize this report"))
print(build_prompt("rewrite this email", "casual"))
The def keyword defines a function. The function name is followed by parentheses containing the inputs (called parameters). return sends a value back to whoever called the function.
Build a Tip Calculator + Password Generator
Create a file called day1.py and build both tools using what you learned today.
- Tip calculator: takes bill amount as input, prints tip and total at 15%, 18%, and 20%
- Password generator: uses
import randomandimport string, generates a password of a length you specify - Wrap both in functions and call them from a
if __name__ == "__main__":block
import random
import string
def tip_calculator(bill):
"""Print tip amounts at 15%, 18%, and 20%."""
for pct in [15, 18, 20]:
tip = bill * (pct / 100)
total = bill + tip
print(f"{pct}%: tip=${tip:.2f}, total=${total:.2f}")
def generate_password(length=16):
"""Generate a random strong password."""
chars = string.ascii_letters + string.digits + "!@#$%"
return "".join(random.choice(chars) for _ in range(length))
if __name__ == "__main__":
tip_calculator(84.50)
print(generate_password(20))
Run it: python day1.py
What You Learned Today
- Installed Python and set up a working development environment
- Variables and the four core data types: string, int, float, boolean
- Control flow: if/elif/else, for loops, while loops
- Functions: defining them, calling them, returning values, default parameters
- Built two working programs: a tip calculator and a password generator
Day 2: Lists, Dicts, and JSON
Tomorrow you'll learn the data structures that AI APIs use to talk to you — and how to read any JSON response.
Start Day 2