wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Exceptions and Definitions

Total questions: 12

Worksheet time: 6mins

Name
Class
Date
1.

How many except statements can a try-except statement have?

a)

None

b)

One

c)

Two

d)

Multiple

2.

When is the finally block executed?

a)

when an exception occurs

b)

when no exception occurs

c)

never

d)

always

3.

When will the else part of try-except-else be executed?

a)

always

b)

when an exception occurs

c)

when no exception occurs

d)

never

4.

Can one except block handle multiple exceptions?

a)

Yes

b)

No

c)

May be

d)

Insufficient information

5.

What is the output of the attached python code?

a)

100

b)

0

c)

Zero Division Error Occurred

d)

Another error will occur, program will "crash"

6.

What is the output of the attached python code?

a)

Value error

Finally done

b)

Type error

Finally done

c)

Type error

d)

Value error

e)

Finally done

7.

What term is used to describe data passed into a definition?

a)

Variable

b)

Loop

c)

Constant

d)

Parameter

8.

How do you correctly call this function definition?

a)

def(1)

b)

x=square( )

c)

square(4)

d)

x=square(5)

9.

What is a variable defined inside a definition referred to as?

a)

A static variable

b)

A global variable

c)

A local variable

d)

An automatic variable

10.

Which of the following statements is NOT true?

a)

Definitions are examples of reusable code

b)

Definitions are always appropriate in programs

c)

Using definitions make it easier to "deconstruct" a problem into smaller pieces

d)

Definitions can make programs easier to read and understand

11.

What would the output be for the following program if the user enters 4 and 6?

a)

10

b)

14

c)

16

d)

error

12.

What will be printed?

a)

nothing

b)

5

c)

6

d)

an error message