0
0
Pythonprogramming~10 mins

Importing specific items 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 sqrt function from the math module.

Python
from math import [1]

result = sqrt(16)
print(result)
Drag options to blanks, or click blank then click option'
Apow
Bsqrt
Crandom
Dceil
Attempts:
3 left
💡 Hint
Common Mistakes
Importing the whole math module instead of just sqrt.
Using a function name that does not exist in math.
2fill in blank
medium

Complete the code to import the choice function from the random module.

Python
from random import [1]

items = ['apple', 'banana', 'cherry']
print(choice(items))
Drag options to blanks, or click blank then click option'
Asample
Bshuffle
Crandint
Dchoice
Attempts:
3 left
💡 Hint
Common Mistakes
Importing a function that shuffles the list instead of picking one item.
Using a function that generates random numbers instead of selecting items.
3fill in blank
hard

Fix the error in the code by importing the correct item from the datetime module.

Python
from datetime import [1]

now = datetime.now()
print(now)
Drag options to blanks, or click blank then click option'
Adatetime
Btime
Cdate
Dtimedelta
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'date' or 'time' which do not have the now() method.
Not importing the class named 'datetime'.
4fill in blank
hard

Fill both blanks to import sin and cos from the math module.

Python
from math import [1], [2]

angle = 0.5
print(sin(angle))
print(cos(angle))
Drag options to blanks, or click blank then click option'
Asin
Btan
Ccos
Dlog
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'tan' or 'log' instead of 'cos'.
Importing only one function instead of both.
5fill in blank
hard

Fill all three blanks to import join, split, and exists from their respective modules.

Python
from os.path import [1]
from os.path import [2]
from os.path import [3]

print(join('folder', 'file.txt'))
print(split('folder/file.txt'))
print(exists('folder/file.txt'))
Drag options to blanks, or click blank then click option'
Ajoin
Bsplit
Cexists
Dpath
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing os.path.split with the string method split.
Importing path instead of join, split, or exists.