WorksheetsFunctions and Exceptions
Total questions: 15
Worksheet time: 30mins
Which of the following programs will NOT cause an error?
1
2
3
4
Which of the programs below will print the following output?I would like a green balloon.
1
2
3
4
What will be the output of the following program?
12
code
4
codecodecode
What will be the output of the following program?
Tracy
hello Turtle
Turtle
hello Tracy
What would this program print?
It doesn’t print anything
<>
<><><><>
<><><>
Consider the following functions.
1
2
3
4
What would this program print?
1
2
3
4
Which of the following options is NOT a valid Python function definition?
1
2
3
4
What is the output of this program?Assume the user enters “kipp52”, then “baseball45”.
1
2
3
4
What will be printed when the program below is run?
12
24
50
66
What is the purpose of exceptions?
To indicate that something has gone wrong, and the program does not know how to continue
To point out when the programmer has written exceptionally good code
To tell the user that he/she has given bad data, such as a negative number instead of a positive number
To allow the programmer to write bad code, but have it still work
What will be printed to the screen if the inputs given to the program below are 1.2, -4, hi, 5 ?
1
2
3
4
Which of the following inputs to the program below would print a statement containing Your number:
Four
5
3.0
*
What line of code should be written after the function definition to add two single-digit values and print the sum?
1
2
3
4
Why do programmers use try and except statements when their code might throw an exception?
So that the programmer can disregard the exception and do what he/she wants anyways
Because Python requires it
To handle exceptions gracefully and either handle the error or print out a useful error message.
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.
