CS: Functions and Parameters
Writing reusable code with inputs and return values
Writing reusable code with inputs and return values
CS - Grade 9-12
- 1
In your own words, explain what a function is in programming and why programmers use functions.
- 2
What is a parameter? Explain how a parameter is different from an argument.
- 3
Consider this Python function: def greet(name): return "Hello, " + name. What is the parameter, and what is the return value when the function is called as greet("Maya")?
- 4
Write a Python function named square that takes one parameter named number and returns number multiplied by itself.
- 5
Trace the following code and state the final value stored in result: def add_tax(price): return price * 1.08 result = add_tax(50)
- 6
A function is defined as def calculate_total(cost, quantity): return cost * quantity. What are the parameters, and what value is returned by calculate_total(7, 4)?
- 7
Explain the difference between printing a value inside a function and returning a value from a function.
- 8
Find and fix the error in this function call: def average(a, b): return (a + b) / 2 score = average(80)
- 9
Write a Python function named is_passing that takes one parameter named score and returns True if score is greater than or equal to 60, otherwise returns False.
- 10
Consider this code: def double(x): return x * 2 def add_three(y): return y + 3 value = add_three(double(5)). What is the final value of value?
- 11
A programmer writes this function: def discount(price, percent): return price - percent. Explain why this function may not correctly calculate a percent discount, and write a better return statement.
- 12
Design a function named format_username that takes two parameters, first_name and last_name, and returns a username made from the first three letters of the first name plus the first three letters of the last name, all lowercase. Describe what format_username("Jordan", "Smith") should return.
Related Cheat Sheets
More CS Worksheets
CS: Algorithms and Flowcharts
Grade 6-8 · 12 problems
CS: Arrays and Lists
Grade 9-12 · 12 problems
CS: Big-O Notation and Algorithm Efficiency
Grade 9-12 · 12 problems
CS: Binary Numbers and Number Systems
Grade 6-8 · 12 problems
More Grade 9-12 Worksheets
Linear Equations
Math · 8 problems
Cell Biology
Biology · 8 problems
Reading Comprehension
Language Arts · 8 problems
Historical Thinking & Evidence
Social Studies · 8 problems