---
title: "Defining a Function with Parameters"
description: "Giving a named block of code a job of its own and passing values into it, so the same steps run on different data."
canonical: https://lightmysky.com/learn/computing/defining-a-function-with-parameters-mt_pyo7yBg4H3
source: https://lightmysky.com/learn/computing/defining-a-function-with-parameters-mt_pyo7yBg4H3.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`.

# Defining a Function with Parameters

Giving a named block of code a job of its own and passing values into it, so the same steps run on different data.

Subject: Computing · Area: Programming · Ages 15 to 16
Page: https://lightmysky.com/learn/computing/defining-a-function-with-parameters-mt_pyo7yBg4H3

## Ready when they can

- Define a function and call it more than once with different arguments
- Decide which values the function needs as parameters
- Replace a repeated block with a single call

## Lesson: Name it once, call it anywhere

A function, also called a procedure here, puts reusable statements under one name. In Python, def starts its definition. Defining it does not run its body; calling it does. For example, singBingo prints B, I, N, G and O once per call. Functions may print text, return a value to the caller, or do both. Reusing a definition does not remove the work performed by each call.

**Example.** Parameters name inputs; arguments supply their values. In sayHello(person), the body print("Hello", person) uses the caller's person value.
```python
def offset(value):
    return value + 4
result = offset(3)
```
return sends 7 back to this caller; it does not print 7. A later call can supply another value.

*(drawing: This call fills person with the argument used by the greeting body.)*

reportGrade(studentName, numCorrect) prints a name and a score: (numCorrect / 30) * 100. For Jo with 27 correct, the score is 90. studentName needs text; numCorrect needs a number. With positional arguments, the first value fills studentName and the second fills numCorrect. Reversing these values gives the body values it cannot use as intended.

The full header def pair(left, right): declares two parameters. Both are required; there are no optional parameters or parameters that collect extra arguments. An ordinary positional call therefore needs exactly two arguments. Python rejects a call with one or three before running this function's body. Other definitions can deliberately accept optional or additional arguments.

To replace four identical greeting blocks, define their steps once and put a call at each old location. If a value varies, make that value a parameter. Keep every required use of the greeting. Editing the shared definition then changes what later calls do. Pick a name that describes the job.

**Recap.** Put repeated steps in a named procedure. Use parameters to pass inputs for each call, and call the procedure wherever you need it.

*Procedure and parameter teaching adapted from Khan Academy's Defining a procedure and Procedures with parameters, with independently written Python explanations and assessment repairs.*

## Practice

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

## Needs first

- [Traversing a List to Build a Result](https://lightmysky.com/learn/computing/traversing-a-list-to-build-a-result-mt_lusbjHFt95)

## Opens up

- [Return Values and Variable Scope](https://lightmysky.com/learn/computing/return-values-and-variable-scope-mt_jivtTHpZc7)
- [Classes and Objects: Bundling Data with Behaviour](https://lightmysky.com/learn/computing/classes-and-objects-bundling-data-with-behaviour-mt_kRvg7LZ_kk)
