Python Street

Welcome to Python Street

Learn the Python concepts that power AI City β€” through tiny shops, delivery trucks, and friendly robot workers.

Start Exploring ✨
Byte: β€œPython is just how AI workers give instructions to machines!”
Section 01

πŸͺ Variables Shop

Variables are labeled containers that store information. Pop a value into a box and watch it light up.

Current
city_name = "AI City"
πŸ“¦ city_name
empty
πŸ“¦ score
empty
πŸ“¦ color
empty
Section 02

πŸ›  Functions Workshop

Functions are reusable instructions. Press a button to activate a worker robot.

def deliver(package):
    return f"{package} delivered!"
Parameter
Return Value
No delivery yet.
Reusable Workflow
Same function, different package input.
Runs: 0
Cause
πŸ—ΊοΈ map
Input package
Effect
πŸ€–
Navigator mode
Result updates after run.
def make_pizza():
    return "πŸ• hot pizza ready!"
Section 03

🚚 Lists Delivery Center

Lists store multiple items in order. Load and unload your delivery truck.

🚚 delivery truck
Indexing + Iteration

Pick an index to light up a package.

tasks = ["travel", "hotel", "budget"]
Section 04

πŸ“’ Dictionaries Address Book

Dictionaries connect a label to its value. Tap a key to open its drawer.

worker = {
  "name": "Planner",
  "tool": "Maps"
}
Section 05

🏭 Classes Worker Factory

Classes are blueprints used to stamp out objects. Press the blueprint to mint workers.

β‘  Class Blueprint
class Agent:
    def __init__(self, role):
        self.role = "Planner"

    def work(self):
        return "Building a city route"
Pick a role

Plans routes and city paths

β‘’ Objects created
🏭Instantiate a blueprint to create workers.
Section 06

πŸ“¦ Imports Station

Imports let you load extra tools into your program. Pick a module to see what it unlocks.

Import + usage
import math

math.sqrt(16)   # 4.0
math.pi         # 3.14159
math.floor(2.9) # 2

Built-in math functions and constants.

Call β†’ Result
math.sqrt(16)β†’4.0
math.pi→3.14159
math.floor(2.9)β†’2
import math
Section 07

πŸ—‚οΈ File I/O Station

Python can read, write, and append files on disk. Pick a mode to see how it works.

Code example
# 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.

Key points
  • β–Έopen(file, "r") opens for reading.
  • β–Έwith ... as f: automatically closes the file.
  • β–Έf.read() returns the whole file as a string.
  • β–Έf.readlines() returns a list of lines.
open("file.txt", "r")
Section 08

πŸ›€ Loops Conveyor Road

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.

Section 09

🎯 Mini Python Missions

Tap a mission card when you understand the idea β€” collect the badges.

Section 10

πŸ” Code Reveal

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)
  • "AI City" is a string value.
  • welcome_city(name) uses a function parameter.
  • Calling welcome_city(city_name) shows visible output.
Section 11

🧠 Advanced AI Prep

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.

🚦Why this matters before AI
  • if / elif / else controls decisions.
  • Boolean expressions decide which branch runs.
  • This shows up everywhere in model routing and validation.
Ready for AI when you can: decide, loop safely, recover from errors, and read JSON.
Section 12

⚑ Final City Challenge

Combine the four ingredients to power Python Street and stabilize AI City.

Combine all four ingredients to stabilize the city ✨

You now understand the Python powering AI City

Next: learn how AI City systems communicate through FastAPI.

Continue Journey