Chapter 0 · Section 4 practice
Functions, Formatting and Error Handling
These questions review the examples in the companion slides. Choose an answer, then check the explanation.
Question 1
def show(x): print(x) then r = show(5). What is r?
5None"5"- A
TypeError
Question 2
def add_city(c, cities=[]): cities.append(c); return cities. After add_city(“NYC”), what does add_city(“LA”) return?
["LA"][]["NYC", "LA"]- A
TypeError
Question 3
demo(a, b=10, *args, scale=1.0, **kwargs) returns (a + b + sum(args)) * scale. What is demo(1, 2, 3, 4, scale=0.5)[“total”]?
10.05.011.02.5
Question 4
x = “global”; def demo(): x = “local”; return x. What do print(demo()) and print(x) show?
localthengloballocalthenlocalglobalthenglobal- An
UnboundLocalError
Question 5
list(zip([“Ana”, “Bo”, “Cy”], [88, 92])) returns?
[("Ana", 88), ("Bo", 92), ("Cy", None)][("Ana", 88), ("Bo", 92)]- A
ValueError [("Ana", "Bo", "Cy"), (88, 92)]
Question 6
Which exception does int(“abc”) raise?
KeyErrorTypeErrorIndexErrorValueError