---
title: "Decomposing a Problem into Subprograms"
description: "Splitting a task into parts small enough to write and check one at a time, then wiring the parts together into the whole program."
canonical: https://lightmysky.com/learn/computing/decomposing-a-problem-into-subprograms-mt_P293LckCnd
source: https://lightmysky.com/learn/computing/decomposing-a-problem-into-subprograms-mt_P293LckCnd.md
retrieved: 2026-11-12
---

> **Agent view.** This is the Markdown twin of the page, for tools and assistants.
> When to use this site, and the call that answers each job: https://lightmysky.com/agent-instructions.md
> API description (OpenAPI 3.1): https://lightmysky.com/openapi.json · Authentication: https://lightmysky.com/auth.md
> Pricing: https://lightmysky.com/pricing.md · Catalog: https://lightmysky.com/llms.txt · Full catalog: https://lightmysky.com/llms-full.txt
> Every machine-readable file on this domain: https://lightmysky.com/.well-known/ai-catalog.json
> Ask for Markdown with `Accept: text/markdown`, a `.md` address, or `?mode=agent`.

# Decomposing a Problem into Subprograms

Splitting a task into parts small enough to write and check one at a time, then wiring the parts together into the whole program.

Subject: Computing · Area: Programming · Ages 15 to 16
Page: https://lightmysky.com/learn/computing/decomposing-a-problem-into-subprograms-mt_P293LckCnd

## Ready when they can

- Break a described program into three or four named jobs before writing any code
- Explain how to test a function on its own with chosen inputs and expected results
- State what each part takes in and what it gives back

## Lesson: Small jobs first, big program later

You have passed arguments into functions and returned results. Decomposition uses those skills to split a larger program into named jobs. Plan the jobs before writing their code. Give each function a clear responsibility. If one function collects input, checks an answer and displays a message, you can separate those jobs to test answer checking without keyboard input or screen output.

**Example.** For one round of rock, paper, scissors, plan four jobs: get the first pick, get the second pick, decide the result, then announce it. The first two jobs can call the same get_choice function. decide_winner compares the picks and applies the rules: rock beats scissors, scissors beats paper, and paper beats rock. Equal picks give a draw.

*(drawing: Two calls reuse one input function. Comparing picks and applying winning rules form one decision job.)*

State each function's arguments, returned result and other actions. Here, get_choice() takes no arguments, reads one valid keyboard pick and returns it. decide_winner(first, second) takes both picks and returns "first player", "second player" or "draw". announce_result(result) takes that result and prints a message. With no explicit return, Python returns None. Printing is this function's useful action.

Test each function with chosen inputs and expected results. Before building keyboard input, test decide_winner directly. Rock against rock should return draw. Include tests for both players winning too. Compare each actual result with its expected result. Then test the joined program: correct parts can still receive the wrong values or be called in the wrong order.

For a new job, identify the information it needs and the result its caller needs next. In a classroom grid simulation, a robot's decision function can take a square's description and return move or wait. Another function collects the description; another carries out the chosen action. Some functions take no arguments, and some perform an action rather than return useful data.

**Recap.** Plan named jobs with clear responsibilities. State arguments, results and actions. Compare each part's results with expectations, then test their connections.

*Lesson, questions, diagrams and flashcards about planning and testing subprograms independently written for this dataset.*

## Practice

8 questions on this page, each with its working shown.

## Needs first

- [Return Values and Variable Scope](https://lightmysky.com/learn/computing/return-values-and-variable-scope-mt_jivtTHpZc7)

## Opens up

- [The Project Arc: Building a Program in Stages](https://lightmysky.com/learn/computing/the-project-arc-building-a-program-in-stages-mt_hACOaB3nA_)
- [Functions at Depth: Default and Keyword Arguments](https://lightmysky.com/learn/computing/functions-at-depth-default-and-keyword-arguments-mt_SR8RhRmYhz)
