Challenge - 5 Problems
Module Path Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of sys.path modification
What will be the output of this code snippet?
Python
import sys sys.path.append('/my/custom/path') print('/my/custom/path' in sys.path)
Attempts:
2 left
💡 Hint
Appending a path to sys.path adds it to the list of module search paths.
✗ Incorrect
Appending '/my/custom/path' to sys.path adds it to the list. Checking membership returns True.
❓ Predict Output
intermediate2:00remaining
Effect of sys.path.insert on module search order
What will be printed by this code?
Python
import sys sys.path.insert(0, '/first/path') print(sys.path[0])
Attempts:
2 left
💡 Hint
Inserting at index 0 places the path at the start of sys.path.
✗ Incorrect
sys.path.insert(0, ...) adds the path at the beginning, so sys.path[0] is '/first/path'.
❓ Predict Output
advanced2:00remaining
Output of sys.path after removing an element
What will be the output of this code?
Python
import sys original_len = len(sys.path) removed = sys.path.pop(0) print(len(sys.path) == original_len - 1 and removed != '')
Attempts:
2 left
💡 Hint
Popping index 0 removes the first element and reduces length by one.
✗ Incorrect
pop(0) removes the first element, so length decreases by 1 and removed is a non-empty string.
🧠 Conceptual
advanced2:00remaining
Understanding sys.path and module import
If a module named 'mymodule' exists in both '/path1' and '/path2', and sys.path is ['/path2', '/path1'], which module will Python import when you run
import mymodule?Attempts:
2 left
💡 Hint
Python searches sys.path in order and imports the first matching module.
✗ Incorrect
Python imports the first found module in sys.path order, so '/path2' module is imported.
❓ Predict Output
expert2:00remaining
Result of modifying sys.path during import
What will be the output of this code?
Python
import sys sys.path = ['/new/path'] + sys.path print(sys.path[0])
Attempts:
2 left
💡 Hint
Prepending a new path to sys.path changes the first element.
✗ Incorrect
The new list has '/new/path' as first element, so sys.path[0] is '/new/path'.