Python Functions and Parameters Quiz

Python Functions and Parameters Quiz

12th Grade

20 Qs

quiz-placeholder

Similar activities

Повторение  мод2

Повторение мод2

9th - 12th Grade

17 Qs

Python Programming

Python Programming

3rd Grade - University

17 Qs

Python - Selection (IF statements)

Python - Selection (IF statements)

9th - 12th Grade

17 Qs

Computer Literacy

Computer Literacy

10th - 12th Grade

21 Qs

Pre-Test-Week 4_type of Media

Pre-Test-Week 4_type of Media

12th Grade

15 Qs

EXCEL CORE Lesson 3 & 4 Test

EXCEL CORE Lesson 3 & 4 Test

9th - 12th Grade

20 Qs

Tes Coba Yuk

Tes Coba Yuk

12th Grade

15 Qs

Programming Fundamentals

Programming Fundamentals

KG - University

20 Qs

Python Functions and Parameters Quiz

Python Functions and Parameters Quiz

Assessment

Quiz

Other

12th Grade

Medium

Created by

ruth sutton

Used 2+ times

FREE Resource

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.

Create a free account and access millions of resources

Create resources
Host any resource
Get auto-graded reports
or continue with
Microsoft
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?