Challenge - 5 Problems
NumPy Import Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate1:30remaining
What is the output of importing NumPy and checking its version?
Consider the following code that imports NumPy and prints its version.
What will be the output?
What will be the output?
NumPy
import numpy as np print(np.__version__)
Attempts:
2 left
💡 Hint
NumPy stores its version in the __version__ attribute as a string.
✗ Incorrect
When you import NumPy as np, np.__version__ returns the version string installed in your environment, such as "1.24.2". It does not raise an error if NumPy is installed.
❓ Predict Output
intermediate1:30remaining
What error occurs if NumPy is not installed and you try to import it?
What error will this code produce if NumPy is not installed in your Python environment?
import numpy
NumPy
import numpyAttempts:
2 left
💡 Hint
Python raises a specific error when a module cannot be found.
✗ Incorrect
If NumPy is not installed, Python raises ModuleNotFoundError when you try to import it. ImportError is a more general error but ModuleNotFoundError is the specific subclass.
🚀 Application
advanced1:30remaining
Which command correctly installs NumPy using pip?
You want to install NumPy in your Python environment using pip. Which command will do this correctly?
Attempts:
2 left
💡 Hint
The pip command to install a package is 'pip install package_name'.
✗ Incorrect
The correct pip command to install NumPy is 'pip install numpy'. Other options are invalid commands.
🔧 Debug
advanced2:00remaining
Why does this import statement cause an error?
Look at this code:
Why does it cause an error?
import numpy as npy print(np.__version__)
Why does it cause an error?
NumPy
import numpy as npy print(np.__version__)
Attempts:
2 left
💡 Hint
Check the alias used in the import and the variable used in print.
✗ Incorrect
The code imports numpy as 'npy' but tries to print 'np.__version__'. Since 'np' is not defined, it raises a NameError.
🧠 Conceptual
expert1:30remaining
What is the main reason to use 'import numpy as np' instead of 'import numpy'?
Why do most Python users write 'import numpy as np' instead of just 'import numpy'?
Attempts:
2 left
💡 Hint
Think about how programmers write code efficiently.
✗ Incorrect
Using 'import numpy as np' creates a short alias 'np' so you can write 'np.array()' instead of 'numpy.array()', making code shorter and easier to read.