wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Functions and Programming Concepts Worksheet

Total questions: 20

Worksheet time: 10mins

Name
Class
Date
1.

What is Top-Down Design?

a)

A method that starts with small details and builds up to the main problem

b)

A method where you start with the big problem first, then break it down into smaller parts until each is simple enough to solve

c)

A bottom-up approach focusing only on code reuse

d)

A technique for debugging functions only

2.

According to the document, why are functions essential for large software projects?

a)

They allow a single programmer to handle everything alone

b)

They reduce code duplication, increase modularity, and enable team collaboration by breaking problems into sub-problems

c)

They eliminate the need for variables

d)

They automatically handle recursion without planning

3.

What is a function in Python?

a)

A block of code that runs only once at the start of the program

b)

A block of organized, reusable code that performs a single, related action and provides modularity

c)

A type of variable that stores data permanently

d)

A keyword used only for printing output

4.

Which of the following is an example of a built-in function in Python?

a)

A user-defined greet() function

b)

print()

c)

A recursive factorial() function

d)

A lambda function for sorting

5.

How do you define a basic function in Python?

a)

Using the 'function' keyword followed by the name

b)

Using 'def' followed by the function name and parentheses, with indented code block

c)

Using 'lambda' for all functions

d)

By declaring variables inside a loop

6.

What is the difference between actual parameters and formal parameters?

a)

Actual parameters are placeholders in the function definition; formal are values passed during the call

b)

Actual parameters are values passed to the function; formal parameters are placeholders in the definition

c)

There is no difference; they are synonyms

d)

Actual parameters must include data types; formal do not

7.

In the example def greet(name, age): print(f"Hello {name}! You are {age} years old."), what are "name" and "age" when calling greet("Alice", 25)?

a)

name="Alice" and age=25 are actual parameters

b)

name and age are formal parameters

c)

name and age are both variables

d)

name and age are arguments only

8.

What happens when arguments are passed to a function?

a)

The values are copied to the corresponding parameters inside the function

b)

The function name is changed to match the arguments

c)

Arguments are always returned immediately

d)

No copying occurs; references are shared globally

9.

Which type of argument allows passing values in any order by specifying parameter names?

a)

Positional arguments

b)

Default arguments

c)

Keyword arguments

d)

Arbitrary arguments (*args)

10.

In def func(name, job='developer'); print(name, 'is a', job), what is printed if called as func('Bob')?

a)

Bob is a

b)

Error: Missing job argument

c)

Bob is a developer

d)

developer is a Bob

11.

What does *args allow in a function?

a)

Fixed number of positional arguments only

b)

Collecting unmatched positional arguments into a tuple for variable length

c)

Only keyword arguments with defaults

d)

Returning multiple values automatically

12.

What is the output of print_args(1, 54, 60) for def print_args(*args): print(args)?

a)

1 54 60

b)

[1, 54, 60]

c)

(1, 54, 60)

d)

Error: Too many arguments

13.

What does a return statement do in a function?

a)

It prints the value to the console

b)

It ends the function call and sends data back to the caller; without it, returns None

c)

It defines new parameters

d)

It creates a global variable

14.

How can a function return multiple values?

a)

By using a list only

b)

By separating values with a comma, which packs them into a tuple

c)

Using print statements

d)

It cannot return multiple values

15.

What is function composition?

a)

Nesting functions inside each other permanently

b)

Using the output of one function as input to another, like math.sin(3602math.pi)

c)

Breaking code into modules only

d)

Recursively calling the same function

16.

In a nested function example like def outer(a, b): def inner(c, d): return c + d; return inner(a, b), what does outer(2, 4) return?

a)

Error: Nested functions not allowed

b)

6

c)

(2, 4)

d)

None

17.

What is the base case in the recursive countdown(num) function?

a)

When num > 0, print num and recurse

b)

When num <= 0, print 'Stop'

c)

Always recurse until num=1

d)

No base case is needed

18.

What is the scope of a variable declared inside a function?

a)

Global: Accessible everywhere

b)

Local: Limited to the function block

c)

Enclosing: Only in nested functions

d)

Universal: Across all files

19.

In the lambda function filter(lambda x: x % 2 == 0, [1,2,3,4]), what does it do?

a)

Prints all numbers

b)

Filters even numbers: [2,4]

c)

Sums the list

d)

Sorts the list descending

20.

What is a decorator in Python?

a)

A way to define anonymous functions only

b)

A function that takes another function as input and returns a modified version, e.g., for logging or timing

c)

A type of recursion

d)

A global variable wrapper