Learn the Python concepts that power AI City β through tiny shops, delivery trucks, and friendly robot workers.
Start Exploring β¨Variables are labeled containers that store information. Pop a value into a box and watch it light up.
Functions are reusable instructions. Press a button to activate a worker robot.
def deliver(package):
return f"{package} delivered!"def make_pizza():
return "π hot pizza ready!"Lists store multiple items in order. Load and unload your delivery truck.
Pick an index to light up a package.
tasks = ["travel", "hotel", "budget"]Dictionaries connect a label to its value. Tap a key to open its drawer.
worker = {
"name": "Planner",
"tool": "Maps"
}Classes are blueprints used to stamp out objects. Press the blueprint to mint workers.
class Agent:
def __init__(self, role):
self.role = "Planner"
def work(self):
return "Building a city route"Plans routes and city paths
Imports let you load extra tools into your program. Pick a module to see what it unlocks.
import math
math.sqrt(16) # 4.0
math.pi # 3.14159
math.floor(2.9) # 2Built-in math functions and constants.
math.sqrt(16)β4.0math.piβ3.14159math.floor(2.9)β2Python can read, write, and append files on disk. Pick a mode to see how it works.
# Read entire file
with open("log.txt", "r") as f:
content = f.read()
# Read line by line
with open("log.txt", "r") as f:
for line in f:
print(line.strip())
# Read all lines into a list
with open("log.txt", "r") as f:
lines = f.readlines()Open a file and read its contents into your program.
Loops repeat actions automatically. Hit play and watch packages roll.
tasks = ["map", "ticket", "hotel", "snack"]
for item in tasks:
deliver(item)Each loop run applies the same action to each item in your list.
Tap a mission card when you understand the idea β collect the badges.
Python code is just instructions that power AI City. Hover the lines to feel each piece.
city_name = "AI City"
def welcome_city(name):
print(f"Welcome to {name}!")
welcome_city(city_name)These are the last Python pieces you will hit immediately in real AI code: conditionals, loop control, error handling, and packages with JSON data.
score = 82
if score >= 90:
level = "excellent"
elif score >= 70:
level = "good"
else:
level = "needs work"
print(level)AI apps constantly branch on conditions like score thresholds, safety checks, or missing inputs.
Combine the four ingredients to power Python Street and stabilize AI City.
Combine all four ingredients to stabilize the city β¨
Next: learn how AI City systems communicate through FastAPI.