Challenge - 5 Problems
Built-in Scope Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ Predict Output
intermediate2:00remaining
Output of shadowing a built-in function
What is the output of this code?
len = 5 print(len([1, 2, 3]))
Python
len = 5 print(len([1, 2, 3]))
Attempts:
2 left
๐ก Hint
Think about what happens when you assign a number to the name 'len'.
โ Incorrect
The variable 'len' is assigned the number 5, so it no longer refers to the built-in function. When you try to call 'len([1, 2, 3])', it tries to call the integer 5 as a function, causing a TypeError.
โ Predict Output
intermediate2:00remaining
Using built-in function after local shadowing
What is the output of this code?
def f():
sum = 10
return sum([1, 2, 3])
print(f())Python
def f(): sum = 10 return sum([1, 2, 3]) print(f())
Attempts:
2 left
๐ก Hint
Inside the function, what does 'sum' refer to?
โ Incorrect
Inside the function, 'sum' is a local variable assigned to 10, so calling 'sum([1, 2, 3])' tries to call the integer 10 as a function, causing a TypeError.
๐ง Debug
advanced2:00remaining
Why does this code raise an error?
This code raises an error. What is the cause?
min = 5 numbers = [3, 1, 4] print(min(numbers))
Python
min = 5 numbers = [3, 1, 4] print(min(numbers))
Attempts:
2 left
๐ก Hint
Check what 'min' refers to after assignment.
โ Incorrect
Assigning 5 to 'min' shadows the built-in function 'min'. Calling 'min(numbers)' tries to call the integer 5 as a function, causing a TypeError.
โ Predict Output
advanced2:00remaining
Output when using built-in after deleting local shadow
What is the output of this code?
max = 10 print(max) del max print(max([1, 5, 3]))
Python
max = 10 print(max) del max print(max([1, 5, 3]))
Attempts:
2 left
๐ก Hint
What happens after deleting the local variable 'max'?
โ Incorrect
First, print(max) prints 10 because 'max' refers to the integer 10 (shadowing the built-in). After 'del max', the name refers back to the built-in function, so print(max([1, 5, 3])) outputs 5.
โ Predict Output
expert2:00remaining
Output of nested function with built-in shadowing
What is the output of this code?
def outer():
list = "not a list"
def inner():
return list([1, 2, 3])
return inner()
print(outer())Python
def outer(): list = "not a list" def inner(): return list([1, 2, 3]) return inner() print(outer())
Attempts:
2 left
๐ก Hint
What does 'list' refer to inside inner()? Is it a function?
โ Incorrect
The variable 'list' in outer shadows the built-in 'list' function. Inside inner(), 'list' refers to the string 'not a list'. Calling 'list([1, 2, 3])' tries to call a string as a function, causing a TypeError.