Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Functions and Exceptions

Total questions: 15

Worksheet time: 30mins

Name
Class
Date
1.

Which of the following programs will NOT cause an error?

a)

1

b)

2

c)

3

d)

4

2.

Which of the programs below will print the following output?I would like a green balloon.

a)

1

b)

2

c)

3

d)

4

3.

What will be the output of the following program?

a)

12

b)

code

c)

4

d)

codecodecode

4.

What will be the output of the following program?

a)

Tracy

b)

hello Turtle

c)

Turtle

d)

hello Tracy

5.

What would this program print?

a)

It doesn’t print anything

b)

<>

c)

<><><><>

d)

<><><>

6.

Consider the following functions.

a)

1

b)

2

c)

3

d)

4

7.

What would this program print?

a)

1

b)

2

c)

3

d)

4

8.

Which of the following options is NOT a valid Python function definition?

a)

1

b)

2

c)

3

d)

4

9.

What is the output of this program?Assume the user enters “kipp52”, then “baseball45”.

a)

1

b)

2

c)

3

d)

4

10.

What will be printed when the program below is run?

a)

12

b)

24

c)

50

d)

66

11.

What is the purpose of exceptions?

a)

To indicate that something has gone wrong, and the program does not know how to continue

b)

To point out when the programmer has written exceptionally good code

c)

To tell the user that he/she has given bad data, such as a negative number instead of a positive number

d)

To allow the programmer to write bad code, but have it still work

12.

What will be printed to the screen if the inputs given to the program below are 1.2, -4, hi, 5 ?

a)

1

b)

2

c)

3

d)

4

13.

Which of the following inputs to the program below would print a statement containing Your number:

a)

Four

b)

5

c)

3.0

d)

*

14.

What line of code should be written after the function definition to add two single-digit values and print the sum?

a)

1

b)

2

c)

3

d)

4

15.

Why do programmers use try and except statements when their code might throw an exception?

a)

So that the programmer can disregard the exception and do what he/she wants anyways

b)

Because Python requires it

c)

To handle exceptions gracefully and either handle the error or print out a useful error message.

d)

Exceptions only are thrown when there are try and except statements. Otherwise, the program will just fail and the programmer will have no idea why it failed.