WorksheetsUnit 6 Review
Total questions: 11
Worksheet time: 8mins
Which of the programs below will print the following output?
I would like a green balloon.
def balloon_choice(color): print("I would like a " + color + " balloon.") balloon_choice("green")
def balloon_choice(color): print("I would like a " + color + " balloon.")
def balloon_choice(): print("I would like a " + color + " balloon.") balloon_choice("green")
def balloon_choice(): print("I would like a green balloon.") balloon_choice("green")
What will be the output of the following program?
12
CODE
4
codecodecode
Which of the following options is NOT a valid Python function definition?
# computes the surface area of a cube of side length 10
# def surface_area(): return 2*(100 + 100 + 100)
# computes the surface area of a rectangular prism
def surface_area(length, width=10, height): return 2*(length width + width height + height * length)
# computes the surface area of a rectangular prism
def surface_area(length, width, height): return 2*(length width + width height + height * length)
# computes the surface area of a rectangular prism
def surface_area(length, width, height=10): return 2*(length width + width height + height * length)
What will be printed when the program below is run?
12
24
50
66
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.
