0
0
NumPydata~20 mins

Installing and importing NumPy - Practice Exercises

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
NumPy Import Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
1: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?
NumPy
import numpy as np
print(np.__version__)
A"1.24.2"
BSyntaxError
CModuleNotFoundError
D"numpy"
Attempts:
2 left
💡 Hint
NumPy stores its version in the __version__ attribute as a string.
Predict Output
intermediate
1: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 numpy
AImportError
BNameError
CModuleNotFoundError
DSyntaxError
Attempts:
2 left
💡 Hint
Python raises a specific error when a module cannot be found.
🚀 Application
advanced
1: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?
Apip install numpy
Binstall numpy
Cpip numpy install
Dpython numpy install
Attempts:
2 left
💡 Hint
The pip command to install a package is 'pip install package_name'.
🔧 Debug
advanced
2:00remaining
Why does this import statement cause an error?
Look at this code:
import numpy as npy
print(np.__version__)

Why does it cause an error?
NumPy
import numpy as npy
print(np.__version__)
AAttributeError because __version__ does not exist
BModuleNotFoundError because numpy is not installed
CSyntaxError due to wrong import syntax
DNameError because 'np' is not defined
Attempts:
2 left
💡 Hint
Check the alias used in the import and the variable used in print.
🧠 Conceptual
expert
1: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'?
ATo install NumPy automatically when importing
BTo shorten the name for easier and faster typing in code
CTo avoid errors when NumPy is not installed
DTo change the version of NumPy used
Attempts:
2 left
💡 Hint
Think about how programmers write code efficiently.