wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Day 4: Python Functions and Exception Handling Quiz

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

What is the purpose of defining a function in Python?

a)

To allow for reusability of code, organization of code, and abstraction of complex logic.

b)

To waste time and effort

c)

To make the code longer and more complicated

d)

To confuse other programmers

2.

What is the difference between parameters and arguments in Python functions?

a)

Parameters are only used in object-oriented programming, while arguments are used in procedural programming.

b)

Parameters are optional in function definitions, while arguments are required.

c)

Parameters are defined in the function signature, while arguments are the actual values passed to the function.

d)

Parameters are used in built-in functions, while arguments are used in user-defined functions.

3.

How do you use the return statement in a Python function?

a)

To import a module from another file

b)

To exit the function and return a value to the caller.

c)

To loop through a list of values

d)

To print a message to the console

4.

What is an exception in Python and why is it important to handle them?

a)

An exception in Python is a type of variable used to store data.

b)

An exception in Python is a feature that enhances the normal flow of a program.

c)

An exception in Python is an event that disrupts the normal flow of a program. It is important to handle them to prevent the program from crashing and to provide a graceful way to deal with unexpected errors.

d)

It is important to handle exceptions to intentionally crash the program.

5.

Explain the syntax and purpose of the try-except block in Python.

a)

The try-except block is used to handle exceptions in Python.

b)

The try-except block is used to create classes in Python.

c)

The try-except block is used to import modules in Python.

d)

The try-except block is used to define a loop in Python.

6.

What is the syntax for defining a function in Python?

a)

functionName(parameters)

b)

def functionName(parameters):

c)

functionName(parameters):

d)

functionName:

7.

How do you pass arguments to a Python function?

a)

By including them within the parentheses when calling the function.

b)

By using a different programming language

c)

By including them in the function name

d)

By sending them as a separate file

8.

What happens if a return statement is not used in a Python function?

a)

The function will throw an error

b)

The function will still execute, but it will not return any value.

c)

The function will return a random value

d)

The function will return None

9.

Give an example of a built-in exception in Python and how to handle it using a try-except block.

a)

IndexError

b)

ZeroDivisionError

c)

ValueError

d)

SyntaxError

10.

What is the purpose of raising an exception in Python and provide an example.

a)

Example: raise KeyError('Key not found')

b)

Example: raise FileNotFoundError('File not found')

c)

Example: raise AttributeError('Attribute error message')

d)

Example: raise NameError('Name not defined')