0
0
Pythonprogramming~20 mins

Built-in scope in Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
๐ŸŽ–๏ธ
Built-in Scope Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ“ Predict Output
intermediate
2: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]))
ANameError
B3
CTypeError
D5
Attempts:
2 left
๐Ÿ’ก Hint
Think about what happens when you assign a number to the name 'len'.
โ“ Predict Output
intermediate
2: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())
ATypeError
BNameError
C6
D10
Attempts:
2 left
๐Ÿ’ก Hint
Inside the function, what does 'sum' refer to?
๐Ÿ”ง Debug
advanced
2: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))
Amin is an integer, so calling min(numbers) causes TypeError
Bmin is not defined, causing NameError
Cnumbers is not iterable, causing TypeError
DSyntaxError due to missing colon
Attempts:
2 left
๐Ÿ’ก Hint
Check what 'min' refers to after assignment.
โ“ Predict Output
advanced
2: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]))
ATypeError\n5
B10\n5
CTypeError\nTypeError
D10\nTypeError
Attempts:
2 left
๐Ÿ’ก Hint
What happens after deleting the local variable 'max'?
โ“ Predict Output
expert
2: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())
A[1, 2, 3]
BSyntaxError
CNameError
DTypeError
Attempts:
2 left
๐Ÿ’ก Hint
What does 'list' refer to inside inner()? Is it a function?