Asked by john
Question: 10
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
Question: 11
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.
Question: 12
What will be the output of the following program?
name = “Tracy”
def print_hello(name):
name = "Turtle"
print(“hello ” + name)
print_hello(name)
Tracy
hello Turtle
Turtle
hello Tracy
Question: 13
What would this program print?
def mystery(num, pattern):
result = ""
for i in range(num):
result = result + pattern
return result
print(mystery(3, "<>"))
It doesn’t print anything
<>
<><><><>
<><><>
Question: 14
What would this program print?
x_pos = 16
y_pos = 20
# Computes the midpoint between (0,0)
# and the point
def compute_distance(x_pos, y_pos):
print("Original Point: " + str(x_pos) + ", " + str(y_pos))
print("Midpoint from Origin: " + str(x_pos/2) + ", " + str(y_pos/2))
compute_distance(12, 14)
print("Point: " + str(x_pos) + ", " + str(y_pos))
Original Point: 16, 20
Midpoint from Origin: 8.0, 10.0
Point: 16, 20
Original Point: 12, 14
Midpoint from Origin: 6.0, 7.0
Point: 12, 14
Original Point: 16, 20
Midpoint from Origin: 8.0, 10.0
Point: 12, 14
Original Point: 12, 14
Midpoint from Origin: 6.0, 7.0
Point: 16, 20
Question: 15
Which of the following inputs to the program below would print a statement containing Your number:
try:
my_number = int(input("Enter an integer: "))
print("Your number: " + str(my_number))
except ValueError:
print("That wasn't an integer!")
Four
5
3.0
*
All Answers 1
Answered by
GPT-5 mini
AI
10 — To indicate that something has gone wrong, and the program does not know how to continue.
11 — To handle exceptions gracefully and either handle the error or print out a useful error message.
12 — hello Turtle
13 — <><><>
14 —
Original Point: 12, 14
Midpoint from Origin: 6.0, 7.0
Point: 16, 20
15 — 5
11 — To handle exceptions gracefully and either handle the error or print out a useful error message.
12 — hello Turtle
13 — <><><>
14 —
Original Point: 12, 14
Midpoint from Origin: 6.0, 7.0
Point: 16, 20
15 — 5
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.