Skip to main content
6 day streak
Skip to lesson
CareerPetalPython field guide
Loading progress...
Course contents
PYTHON FIELD GUIDE

Course contents 72 topics / 15 parts

Full course overviewOriginal coding practice / separate server checks

Essentials first, then internals and engineering trade-offs.

LESSON 02 / GETTING STARTED

Set up a reproducible Python workspace

Install deliberately, debug a small script and distinguish Python from its surrounding tools.

FoundationTutorial 14 min core+12 min deep divePython 3.11+ / 2026-10-27
Saved work unavailable

Save privately stores your edited code, notes and current section. Runs and public checks are not saved as verified scores.

Before you start

Learners building Python foundations; revisit the preparation topics whenever the vocabulary is unfamiliar.

Explore the connected curriculum and preparation map

Lesson content version 2026-10-27. Suggested core budget: 14 minutes; optional deep dive: 12 more minutes. These are reading/practice estimates, not a timed test.

Suggested preparation and repair routes

If an example or checkpoint feels unclear, revisit the relevant foundation and return. These links do not lock the lesson or claim you passed a prerequisite.

Actual runtime and local-lab boundaries

Browser Python 3.13: fresh isolated worker, 4-second execution, 16 KiB output, 256 MiB Python heap; no outbound network, host processes, interactive input or package installation.

Shell, editor and environment setup are local instructions, not a browser terminal or installed toolchain.

Public checks, revealed answers and project self-checks are learning feedback, not verified mastery or problem acceptance. Saving code does not execute it.

YOU WILL BE ABLE TO
  • Explain interpreter, editor and terminal
  • Apply a repeatable first run
  • Reason about choosing your learning route
01

Interpreter, editor and terminal

An interpreter executes Python instructions. An editor stores the source you write, and a terminal is one way to ask tools to run.

READ / UNDERSTAND / THEN EXPERIMENT

Understand first

When a program fails to launch, knowing which tool has which job helps you investigate the right problem rather than installing unrelated packages.

Words you will see

Interpreter
The program that reads and executes Python.
Editor
A tool for writing and saving source text.
Terminal
A text interface used to launch commands in an operating-system shell.

Distinguish source, launcher and runtime

The sample needs no local terminal: the course's browser runner supplies its Python interpreter. sys.version_info describes the running interpreter, not the editor. Comparing its first two version fields with (3, 11) checks a minimum supported Python version.

pathlib.PurePath reads a path's syntax without opening a file. Here it reports the .py suffix of hello.py. A suffix is a naming convention, not proof that a file exists or contains valid Python. The final print shows that sys is the imported module named sys.

Check the runtime before changing tools

For a local workspace, install a supported Python 3 interpreter and save source in a folder you own. Run py --version in a Windows shell or python3 --version where that command is configured. Those are shell instructions, not statements to paste into a Python editor.

An editor may select a different interpreter from your terminal. Check that selection before installing dependencies. Python is useful for automation, services and data work; hard real-time deadlines and CPU-heavy kernels may need another runtime or native components. No new framework is required to learn these basics.

The original example, step by step

These steps explain the original code below. They do not change when you edit your own experiment.

  1. import sys

    Access information about the interpreter executing this code.

  2. print(sys.version_info[:2] >= (3, 11))

    Check the major/minor minimum without printing a machine-specific version.

  3. print(PurePath("hello.py").suffix)

    Inspect the path spelling without filesystem access.

  4. print(sys.__name__)

    Read the imported module's name, not the current script's name.

The interpreter executes Python; an editor helps you write it; a terminal launches commands. Check python3 --version or py --version before installing packages. Start with a supported Python 3.11+ interpreter and a folder you own. Python suits automation, services and data work; hard real-time constraints or CPU-heavy kernels may call for another runtime or native libraries.

Conceptual tool responsibilities; the browser is not a local shell

Conceptual reasoning steps for the original example, not a live trace of your edited Python.

  1. AuthorAn editor holds source text; saving is not execution.
  2. LaunchA local shell command or the browser Run action requests execution.
  3. ExecuteThe selected Python interpreter evaluates the submitted source and produces output or an error.
Predict before you run

Does PurePath('hello.py').suffix prove the file exists?

Separate the tool rolesPYTHON 3

Run your edited Python in the browser, or download it. Ctrl/Cmd + Enter runs. One example runs at a time; each run starts fresh. Save work and place stores a private copy of edited code. Run results remain local learning feedback. No third-party execution service receives your code.

Preparing the editor controls. Run and editing become available when this page is interactive.

Browser Python limits

Python 3.13 with browser-compatible standard-library modules and prebundled SQLite, a 4-second execution limit, 16 KiB output and a 256 MiB Python heap cap. First loading can take up to 45 seconds. Total browser memory is browser-governed. No network, learner package installation, interactive input, host files or system processes. SQLite databases and temporary files disappear after each run. Platform-specific examples may report unsupported modules; download those for a suitable local environment.

Change one thing; explain the difference.

Inspect a different suffix.

Try: Replace "hello.py" with "notes.txt".

The suffix line becomes .txt without reading a file.

Compare a higher minimum.

Try: Replace (3, 11) with (99, 0).

The compatibility result is False on the supported Python 3 runtime.

Before you move on

An editor saves hello.py but no result appears. Has saving necessarily executed the file?

Try explaining it in your own words. Running code is useful, but the explanation above gives you enough to reason it through first.

Read a worked answer

No. Saving stores source. A run action or interpreter command must execute it; in a script, use print for values you want displayed.

This is a self-check, not a required quiz or a saved score. You can revisit any concept.
02

A repeatable first run

A repeatable run executes the intended saved source with known inputs. Debugging compares an expected result with what that run actually did.

READ / UNDERSTAND / THEN EXPERIMENT

Understand first

Changing the wrong file or trusting an old result wastes time. A small deterministic script makes the source-to-output relationship checkable.

Words you will see

Script
A Python source program run as a unit.
REPL
An interactive read-evaluate-print loop that usually displays expression results.
Breakpoint
A debugger instruction to pause before a selected source line.

Predict before changing anything

The sample sets price to 4 and people to 2, multiplies them and prints total: 8. Each input is explicit, so the rule can be checked by hand. A bare total expression in a script would not display the result; print is deliberately present.

For a local run, save this as hello.py, open a shell in that folder and run py hello.py on a configured Windows system, or the appropriate python3 hello.py command on your platform. If another file runs, editing this file cannot change its output. These local commands are not browser Python operations.

Make one controlled change

A breakpoint before total = price * people lets a local debugger inspect the two inputs before calculation. The browser example can instead use explicit print statements. Both methods investigate actual current values; neither is a reason to invent an expected output after an error.

Change one input, predict the new result, run again and compare. Keep four-space indentation inside blocks and use meaningful names. Record the command, supported version and input assumptions with your project. A visible old result does not verify edits made after that run.

The original example, step by step

These steps explain the original code below. They do not change when you edit your own experiment.

  1. price = 4

    Supply the per-person amount.

  2. people = 2

    Supply the number of people.

  3. total = price * people

    Calculate 8 from the current inputs.

  4. print(f"total: {total}")

    Display the computed result with a fixed label.

Create hello.py, save it and run that exact file from its folder. A REPL evaluates expressions interactively; a script needs print to display a result. Use four-space indentation, meaningful names and a debugger breakpoint before adding dependencies. Record commands, expected inputs and supported versions in the project README.

Predict before you run

What makes the original result repeatable?

A repeatable saved scriptPYTHON 3

Run your edited Python in the browser, or download it. Ctrl/Cmd + Enter runs. One example runs at a time; each run starts fresh. Save work and place stores a private copy of edited code. Run results remain local learning feedback. No third-party execution service receives your code.

Preparing the editor controls. Run and editing become available when this page is interactive.

Browser Python limits

Python 3.13 with browser-compatible standard-library modules and prebundled SQLite, a 4-second execution limit, 16 KiB output and a 256 MiB Python heap cap. First loading can take up to 45 seconds. Total browser memory is browser-governed. No network, learner package installation, interactive input, host files or system processes. SQLite databases and temporary files disappear after each run. Platform-specific examples may report unsupported modules; download those for a suitable local environment.

Change one thing; explain the difference.

Change one input.

Try: Set people = 3 before calculating total.

The next run prints total: 12.

Observe an intermediate value.

Try: Add print("inputs:", price, people) before the multiplication.

It displays inputs: 4 2 before total: 8 for the original inputs.

Before you move on

If people is edited to 3 but no new execution occurs, does the old total: 8 verify that edit?

Try explaining it in your own words. Running code is useful, but the explanation above gives you enough to reason it through first.

Read a worked answer

No. The old result belongs to the previous run. A new execution should produce total: 12 for the edited source.

This is a self-check, not a required quiz or a saved score. You can revisit any concept.
03

Inspect your execution context

Execution context is information about the Python process running the source. It helps check compatibility without assuming a particular machine layout.

READ / UNDERSTAND / THEN EXPERIMENT

Understand first

A course sample should be repeatable on the supported runtime and should avoid printing private paths or machine-specific details as if they were fixed outputs.

Words you will see

Standard library
Modules shipped with Python rather than installed as third-party packages.
__name__
The execution name of the current module.
Compatibility check
A test that an environment meets a stated requirement, not an exact environment fingerprint.

Inspect only what the example needs

The original sample imports Path and sys. sys.version_info >= (3, 11) checks whether the running interpreter meets the minimum version. Path('hello.py').suffix returns .py from the path spelling; it does not create, read or run hello.py.

When this code runs as the top-level script, __name__ is '__main__'. An imported module normally has its module name instead. The expected output therefore describes the script runner context, not every possible way of importing these lines.

Separate deterministic checks from observations

Printing an exact interpreter version or absolute working directory can be useful locally, but those outputs differ across machines. The boolean minimum-version check and suffix in this sample avoid those unstable expected values.

Browser Python supplies a constrained environment. It is not your operating-system shell, local folder or package manager. Path syntax is available here, but access to a real local filesystem, installing tools and launching processes require an appropriate local lab rather than a simulated success message.

The original example, step by step

These steps explain the original code below. They do not change when you edit your own experiment.

  1. from pathlib import Path

    Import a standard-library path class.

  2. print(sys.version_info >= (3, 11))

    Display compatibility, not the exact installed version.

  3. print(Path('hello.py').suffix)

    Extract .py without touching a host file.

  4. print(__name__)

    Show __main__ when executed as the top-level program.

The version check is a compatibility check, not an exact-version print. The file suffix and script entry name are deterministic without exposing machine-specific paths.

Predict before you run

Which line actually executes hello.py?

Inspect your execution contextPYTHON 3

Run your edited Python in the browser, or download it. Ctrl/Cmd + Enter runs. One example runs at a time; each run starts fresh. Save work and place stores a private copy of edited code. Run results remain local learning feedback. No third-party execution service receives your code.

Preparing the editor controls. Run and editing become available when this page is interactive.

Browser Python limits

Python 3.13 with browser-compatible standard-library modules and prebundled SQLite, a 4-second execution limit, 16 KiB output and a 256 MiB Python heap cap. First loading can take up to 45 seconds. Total browser memory is browser-governed. No network, learner package installation, interactive input, host files or system processes. SQLite databases and temporary files disappear after each run. Platform-specific examples may report unsupported modules; download those for a suitable local environment.

Change one thing; explain the difference.

Change only the path name.

Try: Replace hello.py with report.json.

The middle output becomes .json; the interpreter and entry context do not change.

Inspect a name with no extension.

Try: Replace hello.py with README.

The middle output is an empty line because suffix returns an empty string.

Before you move on

Would an imported module normally print __main__ for its own __name__?

Try explaining it in your own words. Running code is useful, but the explanation above gives you enough to reason it through first.

Read a worked answer

No. Its execution name is normally its module name. __main__ identifies the top-level entry context, which is why the sample's expected output specifies script execution.

This is a self-check, not a required quiz or a saved score. You can revisit any concept.
DETAILED WALKTHROUGH / NOT JUST A SUMMARY

Where this idea earns its place

Environment problems often look like language problems. A terminal may launch one Python while an editor uses another; a package installed successfully can therefore remain unavailable in the program you actually run. Treat interpreter choice, working directory, source file and environment as separate pieces of evidence rather than reinstalling tools until the symptom disappears.

Follow the mechanism step by step

The command launcher resolves an executable, that interpreter receives a filename, and relative file paths inside the program are resolved against the working directory. Activating a virtual environment changes shell lookup; it does not rewrite every editor setting or already-running process. The interpreter's sys.executable is a useful local diagnostic, but machine-specific paths should not be published in shared logs.

Work through a concrete application

Create a small project folder, confirm the supported interpreter version, and run a minimal script before adding dependencies. Create .venv with that interpreter and invoke its Python explicitly if activation is confusing. Configure the editor to the same interpreter. When installing, use that Python's -m pip, then verify import behaviour from the same launch path used by the application.

Failure cases and misleading shortcuts

Avoid naming your script typing.py, json.py or another standard-library module: your local file may shadow the module you intended to import. Restart a stale REPL after changing dependencies. Do not copy someone else's virtual environment between machines; installed native extensions and interpreter paths may differ. Never mistake a virtual environment for permission isolation.

Cost, ownership and alternatives

An environment per project consumes disk but prevents unrelated projects from sharing an accidental dependency set. Pinning every transitive version can improve reproducibility, while upgrades still need deliberate review. For a standard-library exercise, adding a package manager, container platform and editor extension collection may increase complexity without increasing understanding.

Verify the contract

Write down a clean setup procedure and test it from a fresh environment rather than only your current terminal. Verify the supported Python version, one import, one script invocation and one failing-input example. For a distributable project, later add a build/install test; a script that runs from the repository root does not prove that the packaged application contains all necessary files.

Transfer question: The editor reports ModuleNotFoundError but a terminal import succeeds. What do you compare first?

Compare the interpreter paths and environments used by the two launches, then compare their working directories and module search paths. Install into or select the intended environment rather than globally reinstalling everything. Re-run the same minimal import through both launch methods to prove the diagnosis.

RECALL BEFORE YOU SCROLL

Can you explain it?

Try from memory. Feedback stays on this page and does not award judged progress.

Which tool actually executes a .py file?
TRANSFER THE IDEA

Rebuild: Inspect your execution context

Without copying the worked code, reproduce its observable contract: The version check is a compatibility check, not an exact-version print. The file suffix and script entry name are deterministic without exposing machine-specific paths. Then change one boundary input and explain the result.

Your practice starterPYTHON 3

Run your edited Python in the browser, or download it. Ctrl/Cmd + Enter runs. One example runs at a time; each run starts fresh. Save work and place stores a private copy of edited code. Run results remain local learning feedback. No third-party execution service receives your code.

Preparing the editor controls. Run and editing become available when this page is interactive.

Browser Python limits

Python 3.13 with browser-compatible standard-library modules and prebundled SQLite, a 4-second execution limit, 16 KiB output and a 256 MiB Python heap cap. First loading can take up to 45 seconds. Total browser memory is browser-governed. No network, learner package installation, interactive input, host files or system processes. SQLite databases and temporary files disappear after each run. Platform-specific examples may report unsupported modules; download those for a suitable local environment.

MAKE THE RULE WORK ON NEW INPUTS

Guided practice and transfer

These are public local learning checks, not certified scores. Edited code is saved only with Save work and place. Run results are not stored as certified scores. Export useful unsaved work before leaving.

A short function primer before you begin

def names a reusable rule. The input names in parentheses are parameters. Indent its body; replace the starter's pass placeholder. The body runs when called, not when defined.

return hands a value back and ends that call. print only displays a value. The public assert checks call your function with fresh fixtures; a false condition raises AssertionError with its message.

Return a value, do not only print itPYTHON 3

Run your edited Python in the browser, or download it. Ctrl/Cmd + Enter runs. One example runs at a time; each run starts fresh. Save work and place stores a private copy of edited code. Run results remain local learning feedback. No third-party execution service receives your code.

Preparing the editor controls. Run and editing become available when this page is interactive.

Browser Python limits

Python 3.13 with browser-compatible standard-library modules and prebundled SQLite, a 4-second execution limit, 16 KiB output and a 256 MiB Python heap cap. First loading can take up to 45 seconds. Total browser memory is browser-governed. No network, learner package installation, interactive input, host files or system processes. SQLite databases and temporary files disappear after each run. Platform-specific examples may report unsupported modules; download those for a suitable local environment.

GUIDED PRACTICE

Guided: inspect a script-name convention

Check a path spelling without reading files or launching a process.

The contract

  • filename is a string path spelling.
  • Return a bool that is True exactly when pathlib.PurePath(filename).suffix equals '.py', case-sensitively.
  • Do not access the filesystem or execute the named file. Missing suffix, '.PY' and '.py.txt' do not match.
Guided: inspect a script-name conventionPYTHON 3

Run your edited Python in the browser, or download it. Ctrl/Cmd + Enter runs. One example runs at a time; each run starts fresh. Save work and place stores a private copy of edited code. Run results remain local learning feedback. No third-party execution service receives your code.

Preparing the editor controls. Run and editing become available when this page is interactive.

Browser Python limits

Python 3.13 with browser-compatible standard-library modules and prebundled SQLite, a 4-second execution limit, 16 KiB output and a 256 MiB Python heap cap. First loading can take up to 45 seconds. Total browser memory is browser-governed. No network, learner package installation, interactive input, host files or system processes. SQLite databases and temporary files disappear after each run. Platform-specific examples may report unsupported modules; download those for a suitable local environment.

Inspect 6 public checks

Transparent local learning checks, not exhaustive or tamper-proof grading.

  1. ordinary script
    from copy import deepcopy
    args = ("hello.py",)
    before = deepcopy(args)
    expected = True
    result = has_python_suffix(*args)
    assert type(result) is type(expected) and result == expected, "Return the exact value and type for ordinary script"
    assert args == before, "Preserve every supplied input"
  2. no suffix
    from copy import deepcopy
    args = ("README",)
    before = deepcopy(args)
    expected = False
    result = has_python_suffix(*args)
    assert type(result) is type(expected) and result == expected, "Return the exact value and type for no suffix"
    assert args == before, "Preserve every supplied input"
  3. uppercase suffix
    from copy import deepcopy
    args = ("HELLO.PY",)
    before = deepcopy(args)
    expected = False
    result = has_python_suffix(*args)
    assert type(result) is type(expected) and result == expected, "Return the exact value and type for uppercase suffix"
    assert args == before, "Preserve every supplied input"
  4. extra extension
    from copy import deepcopy
    args = ("hello.py.txt",)
    before = deepcopy(args)
    expected = False
    result = has_python_suffix(*args)
    assert type(result) is type(expected) and result == expected, "Return the exact value and type for extra extension"
    assert args == before, "Preserve every supplied input"
  5. several dots
    from copy import deepcopy
    args = ("lesson.test.py",)
    before = deepcopy(args)
    expected = True
    result = has_python_suffix(*args)
    assert type(result) is type(expected) and result == expected, "Return the exact value and type for several dots"
    assert args == before, "Preserve every supplied input"
  6. empty name
    from copy import deepcopy
    args = ("",)
    before = deepcopy(args)
    expected = False
    result = has_python_suffix(*args)
    assert type(result) is type(expected) and result == expected, "Return the exact value and type for empty name"
    assert args == before, "Preserve every supplied input"
    Can True establish that Python ran the file?

    No. It establishes only the specified lexical suffix. Work depends on path-text length, not file size, because there is no filesystem access.

    GUIDED PRACTICE

    Guided: return calculation and presentation

    Separate a numerical result from its deterministic display text.

    The contract

    • price and people are nonnegative integers.
    • Return a tuple (integer total, string label), where total = price * people and label is exactly 'total: TOTAL'.
    • Preserve zero values; no print, interactive input, file writes or dependency installation.
    Guided: return calculation and presentationPYTHON 3

    Run your edited Python in the browser, or download it. Ctrl/Cmd + Enter runs. One example runs at a time; each run starts fresh. Save work and place stores a private copy of edited code. Run results remain local learning feedback. No third-party execution service receives your code.

    Preparing the editor controls. Run and editing become available when this page is interactive.

    Browser Python limits

    Python 3.13 with browser-compatible standard-library modules and prebundled SQLite, a 4-second execution limit, 16 KiB output and a 256 MiB Python heap cap. First loading can take up to 45 seconds. Total browser memory is browser-governed. No network, learner package installation, interactive input, host files or system processes. SQLite databases and temporary files disappear after each run. Platform-specific examples may report unsupported modules; download those for a suitable local environment.

    Inspect 6 public checks

    Transparent local learning checks, not exhaustive or tamper-proof grading.

    1. original example
      from copy import deepcopy
      args = (4, 2)
      before = deepcopy(args)
      expected = (8, "total: 8")
      result = repeatable_result(*args)
      assert type(result) is type(expected) and result == expected, "Return the exact value and type for original example"
      assert args == before, "Preserve every supplied input"
      assert type(result[0]) is int and type(result[1]) is str, "Respect nested types and ownership promises"
    2. changed people
      from copy import deepcopy
      args = (4, 3)
      before = deepcopy(args)
      expected = (12, "total: 12")
      result = repeatable_result(*args)
      assert type(result) is type(expected) and result == expected, "Return the exact value and type for changed people"
      assert args == before, "Preserve every supplied input"
      assert type(result[0]) is int and type(result[1]) is str, "Respect nested types and ownership promises"
    3. no people
      from copy import deepcopy
      args = (4, 0)
      before = deepcopy(args)
      expected = (0, "total: 0")
      result = repeatable_result(*args)
      assert type(result) is type(expected) and result == expected, "Return the exact value and type for no people"
      assert args == before, "Preserve every supplied input"
      assert type(result[0]) is int and type(result[1]) is str, "Respect nested types and ownership promises"
    4. free price
      from copy import deepcopy
      args = (0, 5)
      before = deepcopy(args)
      expected = (0, "total: 0")
      result = repeatable_result(*args)
      assert type(result) is type(expected) and result == expected, "Return the exact value and type for free price"
      assert args == before, "Preserve every supplied input"
      assert type(result[0]) is int and type(result[1]) is str, "Respect nested types and ownership promises"
    5. both zero
      from copy import deepcopy
      args = (0, 0)
      before = deepcopy(args)
      expected = (0, "total: 0")
      result = repeatable_result(*args)
      assert type(result) is type(expected) and result == expected, "Return the exact value and type for both zero"
      assert args == before, "Preserve every supplied input"
      assert type(result[0]) is int and type(result[1]) is str, "Respect nested types and ownership promises"
    6. one person
      from copy import deepcopy
      args = (7, 1)
      before = deepcopy(args)
      expected = (7, "total: 7")
      result = repeatable_result(*args)
      assert type(result) is type(expected) and result == expected, "Return the exact value and type for one person"
      assert args == before, "Preserve every supplied input"
      assert type(result[0]) is int and type(result[1]) is str, "Respect nested types and ownership promises"
      Why return the integer as well as a label?

      Other code can calculate with the integer without parsing presentation text. There is one multiplication; formatting work and output space grow with the number of displayed digits.

      TRANSFER / TRY BEFORE OPENING HINTS

      Transfer: report mismatched predictions

      The task is now to compare several independently supplied expected results, not just calculate one total.

      The contract

      • records is a list of three-integer tuples (price, people, expected); price and people are nonnegative.
      • Return a new list of one-based integer positions where price * people differs from expected.
      • Keep mismatch order and repeated records. Empty input or all matches returns []; preserve the entire input and use no files or interactive input.
      Transfer: report mismatched predictionsPYTHON 3

      Run your edited Python in the browser, or download it. Ctrl/Cmd + Enter runs. One example runs at a time; each run starts fresh. Save work and place stores a private copy of edited code. Run results remain local learning feedback. No third-party execution service receives your code.

      Preparing the editor controls. Run and editing become available when this page is interactive.

      Browser Python limits

      Python 3.13 with browser-compatible standard-library modules and prebundled SQLite, a 4-second execution limit, 16 KiB output and a 256 MiB Python heap cap. First loading can take up to 45 seconds. Total browser memory is browser-governed. No network, learner package installation, interactive input, host files or system processes. SQLite databases and temporary files disappear after each run. Platform-specific examples may report unsupported modules; download those for a suitable local environment.

      Inspect 6 public checks

      Transparent local learning checks, not exhaustive or tamper-proof grading.

      1. one mismatch
        from copy import deepcopy
        args = ([(4, 2, 8), (4, 3, 8)],)
        before = deepcopy(args)
        expected = [2]
        result = audit_predictions(*args)
        assert type(result) is type(expected) and result == expected, "Return the exact value and type for one mismatch"
        assert args == before, "Preserve every supplied input"
        assert result is not args[0] and all(type(position) is int for position in result), "Respect nested types and ownership promises"
      2. empty records
        from copy import deepcopy
        args = ([],)
        before = deepcopy(args)
        expected = []
        result = audit_predictions(*args)
        assert type(result) is type(expected) and result == expected, "Return the exact value and type for empty records"
        assert args == before, "Preserve every supplied input"
        assert result is not args[0] and all(type(position) is int for position in result), "Respect nested types and ownership promises"
      3. all match
        from copy import deepcopy
        args = ([(3, 4, 12), (0, 5, 0)],)
        before = deepcopy(args)
        expected = []
        result = audit_predictions(*args)
        assert type(result) is type(expected) and result == expected, "Return the exact value and type for all match"
        assert args == before, "Preserve every supplied input"
        assert result is not args[0] and all(type(position) is int for position in result), "Respect nested types and ownership promises"
      4. first mismatch
        from copy import deepcopy
        args = ([(3, 4, 11)],)
        before = deepcopy(args)
        expected = [1]
        result = audit_predictions(*args)
        assert type(result) is type(expected) and result == expected, "Return the exact value and type for first mismatch"
        assert args == before, "Preserve every supplied input"
        assert result is not args[0] and all(type(position) is int for position in result), "Respect nested types and ownership promises"
      5. repeated mismatch
        from copy import deepcopy
        args = ([(2, 2, 3), (2, 2, 3)],)
        before = deepcopy(args)
        expected = [1, 2]
        result = audit_predictions(*args)
        assert type(result) is type(expected) and result == expected, "Return the exact value and type for repeated mismatch"
        assert args == before, "Preserve every supplied input"
        assert result is not args[0] and all(type(position) is int for position in result), "Respect nested types and ownership promises"
      6. zero mismatch
        from copy import deepcopy
        args = ([(5, 0, 1), (0, 3, 0), (1, 2, 0)],)
        before = deepcopy(args)
        expected = [1, 3]
        result = audit_predictions(*args)
        assert type(result) is type(expected) and result == expected, "Return the exact value and type for zero mismatch"
        assert args == before, "Preserve every supplied input"
        assert result is not args[0] and all(type(position) is int for position in result), "Respect nested types and ownership promises"
        Why not return the corrected totals instead?

        The changed requirement is an audit of which predictions disagree, not a replacement of the evidence. It takes one pass over n records and stores at most n mismatch positions.

        A GOOD PLACE TO PAUSE

        Core route complete.

        If you can explain the checkpoint and attempt the practice, move on. Come back for the deep dive when you want the why behind the how.

        Save your core reading milestone

        Environment boundaries

        A virtual environment gives a project its own Python package resolution context. It is not a security sandbox or an automatic record of dependencies.

        READ / UNDERSTAND / THEN EXPERIMENT

        Understand first

        Two projects can require different library versions. Installing into the intended environment avoids accidental interference, while preserving honest security boundaries.

        Words you will see

        Virtual environment
        A project-specific Python environment, commonly created with venv.
        pip
        A package installer that should be invoked with the intended Python interpreter.
        Isolation boundary
        The specific things separated by a mechanism; package isolation does not imply filesystem isolation.

        Bind installation to the interpreter

        Locally, python -m venv .venv creates an environment using the selected interpreter. Use that environment's Python with -m pip to install packages, so the installer and execution runtime agree. Activation is a shell convenience that changes command lookup; PowerShell, cmd and bash use different activation commands.

        The runnable sample does not create or activate an environment. It inspects the folder spelling .venv without filesystem access, then demonstrates the standard signal sys.prefix != sys.base_prefix without printing that machine-specific result. It prints the result's type, bool, instead. The last sentence is true regardless of whether this particular run is inside an environment.

        Keep the limits visible

        An environment normally separates installed third-party packages. It does not prevent Python code from reading files your account can access, and it does not make an untrusted package safe. Avoid installing globally just to work around an interpreter-selection mistake.

        A minimum supported version and an isolated environment are not reproducible dependency pins by themselves. Record project requirements and lock exact dependency resolutions when the project needs that level of repeatability. Browser Run cannot provision your local environment; follow these commands in a real local shell.

        The original example, step by step

        These steps explain the original code below. They do not change when you edit your own experiment.

        1. print(PurePath(".venv").name)

          Inspect the conventional folder name without creating it.

        2. in_environment = sys.prefix != sys.base_prefix

          Inspect the current environment signal.

        3. print(type(in_environment).__name__)

          Display the stable type rather than a machine-specific state.

        4. print("Package isolation is not a security sandbox")

          State the boundary rather than claiming code was sandboxed by venv.

        Create a virtual environment with python -m venv .venv and use its interpreter with python -m pip. Activation commands differ across PowerShell, bash and cmd. Installing a package globally can make one project change another; an environment isolates package resolution, not malicious code or filesystem permissions.

        Predict before you run

        Does inspecting PurePath('.venv').name create a folder?

        Inspect environment concepts without installingPYTHON 3

        Run your edited Python in the browser, or download it. Ctrl/Cmd + Enter runs. One example runs at a time; each run starts fresh. Save work and place stores a private copy of edited code. Run results remain local learning feedback. No third-party execution service receives your code.

        Preparing the editor controls. Run and editing become available when this page is interactive.

        Browser Python limits

        Python 3.13 with browser-compatible standard-library modules and prebundled SQLite, a 4-second execution limit, 16 KiB output and a 256 MiB Python heap cap. First loading can take up to 45 seconds. Total browser memory is browser-governed. No network, learner package installation, interactive input, host files or system processes. SQLite databases and temporary files disappear after each run. Platform-specific examples may report unsupported modules; download those for a suitable local environment.

        Change one thing; explain the difference.

        Inspect a different conventional name.

        Try: Change PurePath(".venv") to PurePath("practice-env").

        The first line becomes practice-env without creating that folder.

        Check the result's allowed values.

        Try: Add print(in_environment in (True, False)).

        It prints True for either environment state; detection is an observation, not an installation.

        Before you move on

        If installing a dependency succeeds but importing it fails in the editor, what should you check first?

        Try explaining it in your own words. Running code is useful, but the explanation above gives you enough to reason it through first.

        Read a worked answer

        Compare the editor's selected interpreter with the interpreter used for python -m pip. A package installed for one interpreter may not be available in another.

        This is a self-check, not a required quiz or a saved score. You can revisit any concept.

        Choosing your learning route

        A useful learning cycle predicts a result, runs current source, compares evidence and makes a small explained change. It is practice, not proof of mastery.

        READ / UNDERSTAND / THEN EXPERIMENT

        Understand first

        Repeating a sample unchanged can hide a misunderstanding. A changed input and a deliberately tested boundary show whether your explanation can adapt.

        Words you will see

        Prediction
        An expected result stated with a reason before execution.
        Assertion
        A check that raises AssertionError if its condition is false.
        Transfer
        Applying an idea after the requirement or context changes.

        Keep evidence tied to the question

        The sample states the expectation 12 for four people at price 3. It computes the total and asserts that total equals the expected value. Only after the assertion succeeds does it print matched: 12. A failed assertion would show an error instead of that success line.

        The second assertion tests an empty case: zero people cost zero. It is a different fixture, not a second proof of every possible input. These public checks are visible learning feedback, not tamper-proof assessment or certification.

        Choose depth and extend deliberately

        Read core plus deep dive by default. For time-boxed revision you can stop after core, but skipping depth is not evidence that you understand it. Recreate an example, explain a failure and keep a short note of the rule you revised.

        Then change the requirement, not only the numbers: for example, calculate money left rather than total spent. A framework or data-science library is a later track, not a prerequisite for this cycle. Browser experiments are not automatically cloud-saved; download work if you need a portable copy.

        The original example, step by step

        These steps explain the original code below. They do not change when you edit your own experiment.

        1. expected = 12

          State the prediction before checking it.

        2. total = price * people

          Run the rule on explicit inputs.

        3. assert total == expected

          Compare actual calculation with the stated prediction.

        4. assert price * 0 == 0

          Check a separate empty-count boundary.

        5. print("zero case: matched")

          Report success only after that assertion passes.

        Read core plus deep dive by default. Switch to core for a time-boxed revision, but do not assume skipping internals proves understanding. Recreate an example, vary an input, explain a failure and keep a short note. Frameworks and data-science libraries are separate follow-on tracks, not prerequisites for this language course.

        Predict before you run

        Does one matching prediction prove every input is correct?

        Check a prediction and a boundaryPYTHON 3

        Run your edited Python in the browser, or download it. Ctrl/Cmd + Enter runs. One example runs at a time; each run starts fresh. Save work and place stores a private copy of edited code. Run results remain local learning feedback. No third-party execution service receives your code.

        Preparing the editor controls. Run and editing become available when this page is interactive.

        Browser Python limits

        Python 3.13 with browser-compatible standard-library modules and prebundled SQLite, a 4-second execution limit, 16 KiB output and a 256 MiB Python heap cap. First loading can take up to 45 seconds. Total browser memory is browser-governed. No network, learner package installation, interactive input, host files or system processes. SQLite databases and temporary files disappear after each run. Platform-specific examples may report unsupported modules; download those for a suitable local environment.

        Change one thing; explain the difference.

        Make an honest mismatch.

        Try: Change people to 5 but leave expected at 12.

        The assertion fails; no success line is substituted.

        Predict the changed input.

        Try: For people = 5, change expected to 15 and explain 3 × 5.

        The assertion passes for that new, independently justified prediction.

        Before you move on

        If price becomes 4 but expected remains 12, what should the program report?

        Try explaining it in your own words. Running code is useful, but the explanation above gives you enough to reason it through first.

        Read a worked answer

        It should raise AssertionError before printing matched. Four people at price 4 cost 16, so the old prediction no longer fits the edited input.

        This is a self-check, not a required quiz or a saved score. You can revisit any concept.

        Make the explanation your own.

        Use Save work and place to store notes with your code. Unsaved edits stay in this course tab; export before leaving. Reading milestones remain separate.

        Take a versioned study copy

        Export this lesson's original theory, textual model explanations, worked examples, public exercise checks and local-runtime boundaries for reading/review. This is separate from exporting your private workspace: no learner code, notes, identity, saved place or results are included. Offline server/browser execution is not provided.

        Worked examples and explained concept checkpoints remain included. Reference answers for independent work are excluded unless you explicitly select them. A downloaded answer is not an earned pass.

        REFLECT, THEN CONTINUE

        Make this a milestone.

        Save a self-reported core reading milestone and confidence. Confidence 1-3 schedules a review when none is already set; higher confidence does not create a new review. This is not a code execution pass or proof of mastery. Deep-dive reading is optional and is not tracked separately yet.

        Your account

        Loading account...

        Sign in to save your work across devices.