Search Header Logo

Python Functions and Parameters Quiz

Authored by ruth sutton

Other

12th Grade

Used 2+ times

Python Functions and Parameters Quiz
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

20 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What keyword is used to define a function in Python?

function

def

define

lambda

Answer explanation

In Python, the keyword 'def' is used to define a function. The other options, 'function', 'define', and 'lambda', are not valid keywords for this purpose. Therefore, 'def' is the correct choice.

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is the output of the following code? def my_function(): return 5 print(my_function())

5

None

my_function()

Error

Answer explanation

The function my_function() returns the value 5. When print(my_function()) is called, it outputs the return value of the function, which is 5. Therefore, the correct answer is 5.

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which of the following is true for procedures in Python?

They always return a value

They are defined using def

They cannot take arguments

They are not supported in Python

Answer explanation

In Python, procedures (functions) are defined using the 'def' keyword. They can return a value, and they can also take arguments, making the statement 'They are defined using def' the only true option.

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What does the following code output? def greet(name="User"): print(f"Hello, {name}") greet()

Hello, User

Hello, name

None

Error

Answer explanation

The function greet has a default parameter 'name' set to 'User'. When called without arguments, it uses this default value, resulting in the output 'Hello, User', which matches the correct answer choice.

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is a parameter?

The name of a function

A value returned by the function

A variable defined in the function header

A keyword to end a function

Answer explanation

A parameter is a variable defined in the function header that allows you to pass information into the function. It is not the function's name, return value, or a keyword to end a function.

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What is an argument?

A placeholder for code

A variable defined inside the function

A value passed to a function when called

A condition for the function

Answer explanation

An argument is a value passed to a function when it is called. This allows the function to operate on different data inputs, making it flexible and reusable.

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What will the following code return? def add(a, b): return a + b print(add(2, 3))

2

3

5

None

Answer explanation

The function 'add' takes two arguments, 'a' and 'b', and returns their sum. When calling 'add(2, 3)', it computes 2 + 3, which equals 5. Therefore, the correct answer is 5.

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?