Chapter 6: Modules and Packages - Python
Chapter 6: Modules and Packages
Fill in the Blanks
1. A _______ in Python is a file containing Python definitions and statements.
Answer: module
2. To create a module, the file must be saved with a _______ extension.
Answer: .py
3. The keyword used to import a module in Python is _______.
Answer: import
4. The _______ module is used to manipulate dates and times in Python.
Answer: datetime
5. The _______ module provides access to mathematical functions.
Answer: math
6. The math.sqrt() function returns the _______ of a number.
Answer: square root
7. The directive %B is used to display the _______ name in full.
Answer: month
True or False
1. A module in Python can only contain one function.
Answer: False
2. The import keyword is used to import a module in Python.
Answer: True
3. The datetime module allows manipulation of both dates and times.
Answer: True
4. The math.factorial() function returns the square root of a number.
Answer: False
5. The %Y directive displays the full year in the datetime module.
Answer: True
6. The math.ceil() function returns the largest integer less than or equal to a given number.
Answer: False
7. The %U directive in the datetime module displays the week number of the year.
Answer: True
Match the Following
Question | Answer |
---|---|
math.sqrt(x) | Returns the square root of x |
%I | Hour in 12-hour format |
import | Used to include a module |
math.pow(x, y) | Returns x raised to the power of y |
%x | Local version of date |
Answer in One Sentence
1. What is a module in Python?
Answer: A module is a file containing Python definitions and statements used to organize code.
2. How do you create a module in Python?
Answer: Create a Python file with a .py extension containing the required code.
3. What is the purpose of the datetime module?
Answer: It is used to manipulate dates and times in Python.
4. What does the math.ceil() function do?
Answer: It returns the smallest integer greater than or equal to a given number.
5. What is the use of the %B directive?
Answer: It displays the full name of the month.
Comments
Post a Comment