Challenge - 5 Problems
Import Aliasing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of alias import usage
What is the output of this Python code using import aliasing?
Python
import math as m result = m.sqrt(16) print(result)
Attempts:
2 left
💡 Hint
Remember that aliasing lets you use a shorter name for a module.
✗ Incorrect
The math module is imported as 'm'. Calling m.sqrt(16) returns the square root of 16, which is 4.0.
❓ Predict Output
intermediate2:00remaining
Effect of aliasing on function call
What will be printed by this code snippet?
Python
from datetime import datetime as dt now = dt.now() print(type(now))
Attempts:
2 left
💡 Hint
Check what dt.now() returns and its type.
✗ Incorrect
The alias 'dt' refers to datetime class. dt.now() returns a datetime object, so its type is .
🔧 Debug
advanced2:00remaining
Identify the error caused by incorrect aliasing
What error does this code raise?
Python
import json as jsn print(json.dumps({'a':1}))
Attempts:
2 left
💡 Hint
Look at the name used to call the function vs the alias.
✗ Incorrect
The module json is imported as jsn, but the code calls json.dumps, which is undefined, causing a NameError.
🧠 Conceptual
advanced2:00remaining
Understanding aliasing effect on namespace
After running this code, which names are defined in the current namespace?
Python
import os as operating_system from math import sqrt as square_root print(square_root(9))
Attempts:
2 left
💡 Hint
Aliasing changes the names you use in your code.
✗ Incorrect
The module os is imported as operating_system, and sqrt is imported as square_root. So only these two names exist in the namespace.
📝 Syntax
expert2:00remaining
Which import aliasing syntax is correct?
Which option correctly imports the module 'collections' with alias 'col'?
Attempts:
2 left
💡 Hint
The 'as' keyword is used after the module name in import statements.
✗ Incorrect
The correct syntax for aliasing a module is 'import module_name as alias'. Other options are invalid syntax.