🐍 Python for Everyone

← Back to exercises

Chapter 30 Practice Bank 70-90 min, hands-on

Practice Bank: CI/CD Pipelines

A deeper set of practice problems, organized by topic, for extra reps beyond the main exercises — including scenario-based problems written in the same style you'll meet in real interviews. This chapter teaches GitHub Actions (YAML-based CI/CD), not Python syntax, so every problem here is a Python function that parses, validates, or reasons about a CI/CD concept using plain data standing in for a workflow file or pipeline state. Standard library only — no installs needed.

Why reason about YAML instead of running real workflows? This site runs your code in a browser sandbox with no GitHub Actions runner and no yaml package available, so every problem models a workflow as plain Python data (a list of strings standing in for YAML lines, dicts for matrix dimensions, booleans for pass/fail state) instead of literally executing a pipeline. Every behavior these problems describe was checked against real GitHub Actions semantics first — the mental model is genuinely correct, just expressed in Python so it can be auto-graded. To practice for real, create a repo, add a workflow file under .github/workflows/, and watch it run in the Actions tab.
How to run these Download starter.py below and run python3 starter.py from inside the same folder. Standard library only — nothing to install.

Topic 1: Why CI/CD Matters

1 Counting manual-deploy outages

Find # TODO 1.1. Write count_broken_by_manual_deploys(deploy_log).

2 Does CI catch bugs before merge?

Find # TODO 1.2. Write catches_bug_before_merge(runs_tests_on_every_push).

3 Debug the Code

Find # TODO 1.3. This wrongly claims CI only benefits large teams. Fix it.

💼 Scenario

Comparing Two Approaches

Find # TODO 1.A. Write choose_deploy_strategy(team_size, deploys_per_week).

💼 Interview Prep

Why CI/CD matters

Find # TODO 1.B. Write explain_why_cicd_matters().

Topic 2: GitHub Actions Basics (workflow files, triggers, jobs, steps, runners)

1 Parsing top-level YAML keys

Find # TODO 2.1. Write parse_top_level_keys(yaml_lines).

2 Does it trigger on pull_request?

Find # TODO 2.2. Write triggers_on_pull_request(yaml_lines).

3 Debug the Code

Find # TODO 2.3. This wrongly claims workflow files can live anywhere in the repo. Fix it.

💼 Scenario

Comparing Two Approaches

Find # TODO 2.A. Write choose_trigger_for_scenario(scenario).

💼 Interview Prep

Runner vs. your local machine

Find # TODO 2.B. Write explain_runner_vs_local().

Topic 3: Building a Lint + Test Workflow

1 Steps run top to bottom

Find # TODO 3.1. Write steps_in_order(step_names).

2 Is the workflow green?

Find # TODO 3.2. Write workflow_fails_fast(lint_passed, test_passed).

3 Debug the Code

Find # TODO 3.3. This wrongly claims the checkout step is optional. Fix it.

💼 Scenario

Comparing Two Approaches

Find # TODO 3.A. Write choose_lint_or_test_first(lint_is_fast, tests_are_slow).

💼 Interview Prep

Why lint before tests

Find # TODO 3.B. Write explain_why_lint_before_test().

Topic 4: Matrix Strategy and Caching

1 Total job runs from a matrix

Find # TODO 4.1. Write matrix_job_count(dimensions).

2 Does the cache key match?

Find # TODO 4.2. Write cache_key_matches(current_key, cached_key).

3 Debug the Code

Find # TODO 4.3. This wrongly adds matrix dimensions instead of multiplying them. Fix it.

💼 Scenario

Comparing Two Approaches

Find # TODO 4.A. Write prevents_version_mismatch(uses_matrix_strategy).

💼 Interview Prep

CI passes locally, fails in the pipeline

Find # TODO 4.B. Write explain_matrix_prevents_version_bugs().

Topic 5: Status Checks and Branch Protection

1 Can this PR merge?

Find # TODO 5.1. Write can_merge_pr(required_checks, passed_checks).

2 Are direct pushes to main blocked?

Find # TODO 5.2. Write blocks_direct_push_to_main(branch_protection_enabled, requires_pr).

3 Debug the Code

Find # TODO 5.3. This wrongly claims a pending check unblocks merging. Fix it.

💼 Scenario

An urgent merge with a failing check

Find # TODO 5.A. Write handle_urgent_broken_check(check_is_flaky_confirmed, has_admin_override).

💼 Interview Prep

Why not skip a required check

Find # TODO 5.B. Write explain_skip_check_temptation().

Topic 6: Beyond Tests (linting, type checking, security scanning, deployment stages)

1 Canonical pipeline stage order

Find # TODO 6.1. Write pipeline_stage_order(stage_names).

2 Is it safe to deploy to production?

Find # TODO 6.2. Write deploy_requires_staging_first(deploys_to_production, passed_staging).

3 Debug the Code

Find # TODO 6.3. This wrongly claims a staging deployment adds nothing if tests pass. Fix it.

💼 Scenario

Comparing Two Approaches

Find # TODO 6.A. Write choose_next_pipeline_addition(has_tests, has_lint, has_type_check, has_security_scan).

💼 Interview Prep

Why tests alone aren't enough

Find # TODO 6.B. Write explain_defense_in_depth_pipeline().

Checking your work Compare your output against solution.py. Your exact wording doesn't need to match on the explanation-style tasks — the goal is that your program runs without errors and does what each TODO asks. Every data-driven task's output is exactly reproducible.
← Exercises Challenges →