Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong module name like 'random' or 'sys'.
Not using 'as' keyword for aliasing.
✗ Incorrect
The math module is imported with alias 'm' to use math functions like sqrt.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'time' instead of 'datetime'.
Forgetting to use alias 'dt' in print statement.
✗ Incorrect
The datetime module is imported as 'dt' to access datetime functions.
3fill in blank
hardFix 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'
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.
✗ Incorrect
The standard module for JSON is 'json', which can be aliased as 'js'.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'choice' instead of 'randint' for integers.
Not aliasing the module correctly.
✗ Incorrect
The random module is aliased as 'rnd' and randint generates a random integer in the range.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'path' instead of 'listdir' to list files.
Not aliasing the os module correctly.
✗ Incorrect
The os module is aliased as 'oper'. getcwd() gets current directory, listdir() lists files.