Week 7 Quiz
Predict, then check: which line does this program print first?
def greet(): print("Hello from inside the function") print("Defined, not yet called") greet() greet()Select one.
- Hello from inside the function
- Defined, not yet called
- Nothing; the def block raises an error first
- Hello from inside the function, printed by the def line
Predict, then check: what does this program print?
def pages_left(goal, pages_read): return goal - pages_read print(pages_left(300, 45))Select one.
- 345
- −255
- 255
- 45
Predict, then check: the arguments are written in a different order. What does this program print?
def pages_left(goal, pages_read): return goal - pages_read print(pages_left(45, 300))Select one.
- −255
- 255
- 0
- TypeError
Predict, then check: what does this program print?
def pages_left(goal, pages_read): return goal - pages_read print(pages_left(200, 45) // 30)Select one.
- 155
- 6
- 8
- 5
Predict, then check: what does this program print?
def show(x): print(x * 2) print(show(4))Select one.
- 8, then None on a second line
- 8 only
- None only
- 8, then 8 again on a second line
Predict, then check: what does this program print?
n = 5 def change(): n = 99 change() print(n)Select one.
- 99
- 5
- None
- NameError
This program prints 8 and then stops with an error. Reading the error from the bottom up, which exception type does its last line name?
def double(x): print(x * 2) y = double(4) print(y + 1)Select one.
- NameError
- SyntaxError
- TypeError
- ValueError
Predict, then check: how many lines does this program print in all?
def greet(): print("Hello from inside the function") print("Defined, not yet called") for i in range(2): greet()Select one.
- 2
- 4
- 1
- 3
Select every line this program prints.
level = 100 def show(): print("inside sees", level) def reset(): level = 0 print("inside", level) show() reset() print("outside", level)Select every option that applies.
- inside sees 100
- outside 0
- inside 0
- outside 100
- inside sees 0
A chatbot claims this program prints a single line, 8, because show returns the value it prints. True or false: running the program confirms the chatbot's claim.
def show(x): print(x * 2) print(show(4))True or false.
- True
- False
Built with The Course Maker · samples.thecoursemaker.com