0
0
Pythonprogramming~10 mins

Import aliasing in Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the math module with an alias 'm'.

Python
import [1] as m
print(m.sqrt(16))
Drag options to blanks, or click blank then click option'
Amath
Bos
Csys
Drandom
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong module name like 'random' or 'sys'.
Not using 'as' keyword for aliasing.
2fill in blank
medium

Complete the code to import the datetime module with alias 'dt' and print current year.

Python
import [1] as dt
print(dt.datetime.now().year)
Drag options to blanks, or click blank then click option'
Atime
Bcalendar
Cdateutil
Ddatetime
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'time' instead of 'datetime'.
Forgetting to use alias 'dt' in print statement.
3fill in blank
hard

Fix the error in the code to import the json module with alias 'js' and load a JSON string.

Python
import [1] as js
json_str = '{"name": "Alice"}'
data = js.loads(json_str)
print(data['name'])
Drag options to blanks, or click blank then click option'
Asimplejson
Bjs
Cjson
Djsonlib
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to import a non-existent module like 'js'.
Using wrong module names like 'jsonlib' or 'simplejson' without installation.
4fill in blank
hard

Fill both blanks to import the random module as 'rnd' and print a random integer between 1 and 10.

Python
import [1] as rnd
print(rnd.[2](1, 10))
Drag options to blanks, or click blank then click option'
Arandom
Brandint
Cchoice
Drandrange
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'choice' instead of 'randint' for integers.
Not aliasing the module correctly.
5fill in blank
hard

Fill all three blanks to import the os module as 'oper', get current working directory, and list files.

Python
import [1] as oper
cwd = oper.[2]()
files = oper.[3](cwd)
print(files)
Drag options to blanks, or click blank then click option'
Aos
Bgetcwd
Clistdir
Dpath
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'path' instead of 'listdir' to list files.
Not aliasing the os module correctly.