Skip to content
Computer Science · Grade 9 · The Art of Programming · Term 1

Function Parameters and Return Values

Students will deepen their understanding of functions by working with parameters to pass data and return values to send results back.

Ontario Curriculum ExpectationsCS.HS.AP.8CS.HS.CT.9

About This Topic

Functions gain power through parameters, which pass specific data into them, and return values, which send computed results back to the caller. Grade 9 students in Ontario's Computer Science curriculum construct functions that accept multiple parameters, perform calculations, and return outputs, such as a function that takes base and height to return triangle area. This builds versatility, allowing the same function to work with different inputs without rewriting code. Students analyze how parameters enable reuse and differentiate action-oriented procedures from value-returning functions.

This topic fits within The Art of Programming unit, advancing from basic functions to modular code design. It supports standards like CS.HS.AP.8 on procedures with parameters and CS.HS.CT.9 on computational thinking through decomposition. Students practice breaking problems into functions, testing them independently before integration, which mirrors professional programming practices and reduces bugs in larger scripts.

Active learning excels for this content because students code, run, and debug functions collaboratively. Pair programming lets them trace parameter flow and return paths step-by-step, spotting errors instantly. Iterative challenges, like chaining functions, make abstract syntax tangible, boost confidence, and solidify skills through immediate feedback.

Key Questions

  1. Analyze how parameters enable functions to be more versatile and reusable.
  2. Construct a function that takes multiple parameters and returns a computed value.
  3. Differentiate between functions that perform an action and those that return a value.

Learning Objectives

  • Analyze how function parameters increase code reusability by allowing functions to operate on different input values.
  • Construct Python functions that accept multiple parameters and return a single computed value based on those parameters.
  • Differentiate between functions designed to perform an action (e.g., printing output) and functions designed to return a computed value for further use.
  • Trace the flow of data into a function via parameters and out of a function via a return statement in a given code snippet.
  • Evaluate the effectiveness of a function based on its parameter design and the clarity of its return value.

Before You Start

Introduction to Functions

Why: Students need a basic understanding of what functions are and how to define and call them before working with parameters and return values.

Basic Data Types (Integers, Floats, Strings)

Why: Understanding different data types is essential for knowing what kind of data can be passed as arguments and what type of value a function can return.

Key Vocabulary

ParameterA variable listed inside the parentheses in a function definition. It acts as a placeholder for data that will be passed into the function when it is called.
ArgumentThe actual value that is sent to the function when it is called. This value is assigned to the corresponding parameter within the function.
Return ValueThe value that a function sends back to the part of the program that called it. This is specified using the 'return' keyword.
Function CallThe act of executing a function. When a function is called, the program jumps to the function's code, passes any arguments, and then returns to the point after the call once the function is complete.

Watch Out for These Misconceptions

Common MisconceptionParameters are global variables that change everywhere.

What to Teach Instead

Parameters create local scopes; changes inside functions do not affect caller variables. Pair tracing activities with print statements reveal scope boundaries clearly, as students step through code line-by-line and observe isolated effects.

Common MisconceptionAll functions must return a value; printing is the same.

What to Teach Instead

Procedures perform actions like printing without returning, while functions compute and return for reuse. Testing both types side-by-side in group challenges shows how unassigned returns discard results, helping students value returns through practical comparisons.

Common MisconceptionReturn statements can only appear at the end of a function.

What to Teach Instead

Returns exit early when conditions met, useful for validation. Debug sessions in small groups expose this by simulating paths, where students adjust code and rerun to see early exits work correctly.

Active Learning Ideas

See all activities

Real-World Connections

  • Software developers building video games use functions with parameters to control character actions. For example, a 'moveCharacter' function might take parameters for direction (e.g., 'up', 'down') and distance, returning the character's new position on the game map.
  • Financial analysts use functions to calculate metrics like loan interest or investment returns. A function to calculate monthly mortgage payments would take parameters such as principal loan amount, interest rate, and loan term, returning the calculated monthly payment.
  • Web developers create functions to handle user input and display dynamic content. A function that processes a user's search query might take the query string as a parameter and return a list of relevant search results to be displayed on a webpage.

Assessment Ideas

Quick Check

Provide students with a Python code snippet containing a function definition with parameters and a function call. Ask them to identify the parameters, the arguments passed, and the expected return value. For example: 'In the function `calculate_area(width, height)`, what are the parameters? If called as `calculate_area(5, 10)`, what are the arguments? What value will this function return?'

Exit Ticket

Give students a scenario: 'You need a function to convert Celsius to Fahrenheit.' Ask them to write the function signature (including parameters) and one line of code showing how they would call it with a specific temperature, and what the expected return value would be. For example: 'Write a function `celsius_to_fahrenheit(celsius_temp)`. Show how to call it with 25 degrees Celsius and state the expected return value.'

Discussion Prompt

Pose the question: 'When might you choose to write a function that simply prints a message versus a function that returns a calculated value? Provide a specific programming example for each case.' Facilitate a brief class discussion where students share their examples and reasoning.

Frequently Asked Questions

How do function parameters improve code reusability?
Parameters let functions accept varied inputs, so one area calculator works for any rectangle dimensions without duplication. Students reuse functions across scripts, cutting errors and saving time. In class, challenges building libraries of parameterized functions show how this scales to complex programs, aligning with professional modularity.
What is the difference between action functions and those that return values?
Action functions, or procedures, execute tasks like displaying messages without outputting data. Return functions compute results for assignment or further use, like math operations. Hands-on tests reveal this: calling a print function shows output but no variable change, while returns enable chaining, clarifying through direct execution.
How can active learning help students understand function parameters and returns?
Pair programming and relay challenges engage students in building, testing, and chaining functions live. They trace data flow visually with prints or debuggers, correcting misconceptions instantly. Collaborative debugging builds deeper insight than lectures, as peers explain parameter passing, making syntax intuitive and skills durable for future coding.
What are common errors with return statements in functions?
Errors include forgetting assignment (value lost), multiple conflicting returns, or returning before processing. Students fix these in iterative coding rounds, where group reviews catch issues early. Tracing execution paths reinforces proper use, turning frequent pitfalls into mastered techniques through repeated, low-stakes practice.