0% found this document useful (0 votes)
17 views15 pages

Python Module Import Keywords Worksheet

Python Modules

Uploaded by

atsagar62
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views15 pages

Python Module Import Keywords Worksheet

Python Modules

Uploaded by

atsagar62
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

SAGAR INTERNATIONAL SCHOOL,

PERUNDURAI.
AFFILIATED NO: 1930419
WORKSHEET
CLASS: XI B,C
SUBJECT: COMPUTER SCIENCE

Python Modules

Section 1: Multiple Choice Questions (MCQs)

1. Which keyword is used to import a module in Python?


a) include
b) import
c) require
d) module
2. What does the 'from' keyword do in a Python import
statement?
a) Imports entire module
b) Imports specific functions or classes from a module
c) Defines a new module
d) Runs the module
3. Which built-in module in Python is used for mathematical
operations?
a) math
b) random
c) os
d) sys
4. How can you import a module and give it an alias?
a) import module as alias
b) import module alias
c) alias = import module
d) module alias = import
5. What function from the 'os' module lists files in a directory?
a) [Link]()
b) [Link]()
c) [Link]()
d) [Link]()
6. Which function is used to find the version of Python in
use?
a) [Link]
b) [Link]()
c) [Link]
d) [Link]()
7. What does the '[Link](1,10)' function do?
a) Returns a random float between 1 and 10
b) Returns a random integer between 1 and 10 inclusive
c) Returns a random integer between 1 and 9
d) Returns a list of random integers
8. Which module is used for regular expressions in Python?
a) regex
b) re
c) expression
d) reg
9. Which of the following is NOT a standard Python module?
a) math
b) numpy
c) sys
d) os
10. How do you import all functions from a module?
a) import module.*
b) from module import *
c) import * from module
d) import [Link]
11. What does the '[Link]()' function do?
a) Starts a new Python process
b) Exits the current Python program
c) Imports system modules
d) Returns system info
12. Which module helps in working with dates and times?
a) datetime
b) time
c) calendar
d) All of the above
13. How can you find the file path of an imported module?
a) [Link]
b) [Link]
c) [Link]
d) [Link]()
14. What does the 'help(module)' function do?
a) Displays documentation of the module
b) Installs the module
c) Updates the module
d) Deletes the module
15. What is the purpose of the '[Link]' file in a package?
a) It contains main program code
b) Marks the directory as a Python package
c) Stores module metadata
d) Is a compiled bytecode file
16. Which module can be used to generate random numbers?
a) random
b) math
c) randomize
d) numbers
17. What will 'import sys; print([Link])' display?
a) Python version
b) Operating system platform
c) Hardware architecture
d) CPU type
18. Which module would you use to work with JSON data?
a) json
b) xml
c) yaml
d) csv
19. How do you reload a previously imported module in
Python 3?
a) reload(module)
b) [Link](module)
c) [Link](module)
d) [Link]()
20. What does the '[Link](16)' function return?
a) 8
b) 4
c) 16
d) 2
21. Which module helps in creating and working with
compressed files?
a) zipfile
b) compress
c) tarfile
d) zipcompress
22. How do you list all functions and variables defined in a
module?
a) dir(module)
b) list(module)
c) [Link]()
d) [Link]()
23. What is the use of 'pip' in Python?
a) Python interpreter
b) Package installer for Python
c) Debugger
d) Documentation tool
24. How can you get the current working directory using 'os'
module?
a) [Link]()
b) [Link]()
c) [Link]()
d) [Link]()
25. Which of these modules is NOT included in Python's
standard library?
a) collections
b) itertools
c) pandas
d) functools

Section 2: Fill in the Blanks

26. The keyword used to import a module is _______.


27. To import specific attributes from a module, we use the
_______ keyword.
28. The 'math' module is used for _______ operations.
29. The function '[Link]()' returns a list of _______.
30. The '[Link]' file marks a directory as a _______.
31. The 'random' module is used to generate _______
numbers.
32. The 'sys' module contains functions related to the
_______ system.
33. To generate a random integer between 1 and 100, we use
_______.
34. The module 're' is used for _______ expressions.
35. The 'json' module helps in working with _______ data.
36. 'import math as m' assigns an _______ to the module.
37. The function '[Link]()' is used to _______ the program.
38. The function 'help()' provides _______ about modules.
39. The 'dir()' function lists all _______ and _______ in a
module.
40. The 'pip' tool is used to _______ Python packages.
41. The 'zipfile' module helps to work with _______ files.
42. The method to get the current working directory is
_______.
43. The module used to work with dates and times is
_______.
44. Reloading a module in Python 3 uses the _______
module.
45. The '[Link]()' function returns the _______ root of a
number.

Section 3: True/False

51. The 'import' keyword is used to load modules in Python.


(True/False)
52. The 'random' module can generate random integers and
floats. (True/False)
53. The '[Link]' file is mandatory for Python 3. (True/False)
54. The '[Link]' returns the current operating system
platform. (True/False)
55. The 'json' module is used to work with XML data.
(True/False)
56. The 'pip' tool is used to install Python packages.
(True/False)
57. The '[Link]()' returns the current working directory.
(True/False)
58. The 're' module helps in handling regular expressions.
(True/False)
59. The '[Link]()' is used to reload a module.
(True/False)
60. The 'dir()' function returns all the methods of a module.
(True/False)
61. The 'math' module provides functions like sin, cos, and
tan. (True/False)
62. The '[Link]()' function excludes the upper limit.
(True/False)
63. The 'zipfile' module cannot be used to extract files.
(True/False)
64. The 'help()' function displays the documentation of a
module. (True/False)
65. The '[Link]()' function terminates the Python interpreter.
(True/False)

Section 4: Assertion and Reasoning

66. Assertion (A): The 'import' keyword is used to bring


modules into a program.
Reason (R): Without import, Python cannot access
module functions.
a) Both A and R are true and R explains A
b) Both A and R are true but R does not explain A
c) A is true but R is false
d) A is false but R is true
67. Assertion (A): The 'random' module can generate random
numbers.
Reason (R): The 'math' module is used for mathematical
operations.
a) Both A and R are true and R explains A
b) Both A and R are true but R does not explain A
c) A is true but R is false
d) A is false but R is true
68. Assertion (A): The '[Link]' file is mandatory in all Python
packages.
Reason (R): It tells Python the directory is a package.
a) Both A and R are true and R explains A
b) Both A and R are true but R does not explain A
c) A is true but R is false
d) A is false but R is true
69. Assertion (A): The '[Link]()' function stops the program.
Reason (R): It exits the Python interpreter.
a) Both A and R are true and R explains A
b) Both A and R are true but R does not explain A
c) A is true but R is false
d) A is false but R is true
70. Assertion (A): The '[Link]()' function reloads a
module.
Reason (R): It helps to update the module without
restarting.
a) Both A and R are true and R explains A
b) Both A and R are true but R does not explain A
c) A is true but R is false
d) A is false but R is true
71. Assertion (A): The 'os' module contains functions to
interact with the operating system.
Reason (R): It allows working with files and directories.
a) Both A and R are true and R explains A
b) Both A and R are true but R does not explain A
c) A is true but R is false
d) A is false but R is true
72. Assertion (A): The 'json' module is used for reading and
writing JSON data.
Reason (R): JSON is a common data interchange format.
a) Both A and R are true and R explains A
b) Both A and R are true but R does not explain A
c) A is true but R is false
d) A is false but R is true
73. Assertion (A): The 'dir()' function lists all names in a
module.
Reason (R): It helps understand module contents.
a) Both A and R are true and R explains A
b) Both A and R are true but R does not explain A
c) A is true but R is false
d) A is false but R is true
74. Assertion (A): The 'pip' tool is used to uninstall Python
packages.
Reason (R): 'pip' manages package installation and
removal.
a) Both A and R are true and R explains A
b) Both A and R are true but R does not explain A
c) A is true but R is false
d) A is false but R is true
75. Assertion (A): The 'help()' function gives documentation
about modules.
Reason (R): It is an interactive way to learn about Python.
a) Both A and R are true and R explains A
b) Both A and R are true but R does not explain A
c) A is true but R is false
d) A is false but R is true

Section 5: Short Answer Questions (2 marks)

76. What is a Python module?


77. How do you import a specific function from a module?
78. What is the use of the 'random' module?
79. How can you find the current working directory?
80. What is the purpose of the '[Link]' file?
81. How do you exit a Python program using the sys module?
82. Name any two modules used for date and time handling.
83. How do you list all functions and variables in a module?
84. What is pip used for in Python?
85. How do you reload a module in Python 3?

Section 6: Short Answer Questions (3 marks)

86. Write a program to import the math module and print the
square root of 25.
87. Explain the difference between import module and from
module import function.
88. Write a program to list files in the current directory using
os module.
89. How does the '[Link]()' function work?
90. Write a program to demonstrate aliasing a module.
91. Explain the role of pip in Python package management.
92. Write a Python program to read JSON data from a string.
93. What are the advantages of using modules in Python?
94. How can you find documentation of a module inside
Python interpreter?
95. Write a program to reload an imported module.
Section 7: Long Answer Questions (4 marks)

96. Describe the purpose and usage of Python modules with


examples.
97. Explain how to install and manage third-party modules in
Python.
98. Write a Python program using the os module to create and
delete a directory.
99. Discuss the difference between Python packages and
modules.
100. Explain how to use the 'importlib' module to reload a
module and why it is useful.

Section 8: Long Answer Questions (5 marks)

101. Write a detailed program demonstrating the use of


multiple Python modules in a single program.
102. Discuss the advantages of modular programming in
Python.
103. Explain the structure of a Python package and the
role of '[Link]'.
104. Write a program to parse JSON data and handle
exceptions.
105. Write a Python program to use pip to install a
package and import it.
Answer Key for the Python Modules worksheet:

Section 1: Multiple Choice Questions (MCQs)

1. b) import
2. b) Imports specific functions or classes from a module
3. a) math
4. a) import module as alias
5. a) [Link]()
6. a) [Link]
7. b) Returns a random integer between 1 and 10 inclusive
8. b) re
9. b) numpy
10. b) from module import *
11. b) Exits the current Python program
12. d) All of the above
13. a) [Link]
14. a) Displays documentation of the module
15. b) Marks the directory as a Python package
16. a) random
17. b) Operating system platform
18. a) json
19. b) [Link](module)
20. b) 4
21. a) zipfile
22. a) dir(module)
23. b) Package installer for Python
24. a) [Link]()
25. c) pandas

Section 2: Fill in the Blanks

26. import
27. from
28. mathematical
29. files/directories
30. package
31. random
32. system
33. [Link](1, 100)
34. regular
35. JSON
36. alias
37. exit
38. information/documentation
39. functions, variables
40. install/manage
41. compressed/zip
42. [Link]()
43. datetime/time
44. importlib
45. square

Section 3: True/False

51. True
52. True
53. False (Not mandatory in Python 3 but used for packages
in Python 2)
54. True
55. False (JSON module is not for XML)
56. True
57. True
58. True
59. True
60. False (dir() returns all names, not only methods)
61. True
62. False ([Link] includes upper limit)
63. False (zipfile can extract files)
64. True
65. True

Section 4: Assertion and Reasoning

66. a) Both A and R are true and R explains A


67. b) Both A and R are true but R does not explain A
68. b) Both A and R are true but R does not explain A
69. a) Both A and R are true and R explains A
70. a) Both A and R are true and R explains A
71. a) Both A and R are true and R explains A
72. a) Both A and R are true and R explains A
73. a) Both A and R are true and R explains A
74. a) Both A and R are true and R explains A
75. a) Both A and R are true and R explains A

Section 5: Short Answer Questions (2 marks)

76. A Python module is a file containing Python definitions


and statements.
77. Using: from module_name import function_name
78. It is used to generate random numbers.
79. By using [Link]() function.
80. It marks the directory as a Python package.
81. By calling [Link]() function.
82. datetime and time modules.
83. By using the dir(module_name) function.
84. pip is used to install and manage Python packages.
85. By using [Link](module) function.

Section 6: Short Answer Questions (3 marks)

86. python
CopyEdit

import math
print([Link](25))

vbnet
CopyEdit
87. `import module` imports the whole module, while `from module
import function` imports only a specific function.
88. ```python
import os
print([Link]('.'))

89. [Link](a, b) returns a random integer N such that


a <= N <= b.
90. python
CopyEdit

import math as m
print([Link](16))

wasm
CopyEdit
91. pip helps install, upgrade, and manage Python packages.
92. ```python
import json
data = '{"name": "John", "age": 30}'
parsed = [Link](data)
print(parsed["name"])

93. Modules help organize code, promote reuse, and make


programs modular.
94. Use help(module_name) inside Python interpreter.
95. python
CopyEdit

import importlib
[Link](module_name)

yaml
CopyEdit

---

### Section 7: Long Answer Questions (4 marks)


96. Modules are files with Python code that can be imported to
reuse functions, classes, and variables. For example, `import
math` to use math functions.
97. Use `pip install package_name` to install third-party modules
and `pip uninstall package_name` to remove them.
98. ```python
import os
[Link]('test_dir')
[Link]('test_dir')

99. A module is a single Python file; a package is a directory


with __init__.py containing multiple modules.
100. The [Link](module) function reloads a
module to reflect code changes without restarting the
interpreter.

Section 8: Long Answer Questions (5 marks)

101. A program importing multiple modules like math, os,


json to perform various tasks such as calculations, file
operations, and JSON parsing.
102. Modular programming divides programs into
separate modules making code reusable, maintainable,
and easier to debug.
103. A Python package is a directory containing an
__init__.py file that tells Python this directory should be
treated as a package.
104. python
CopyEdit

import json
try:
data = '{"name": "Alice"}'
parsed = [Link](data)
except [Link]:
print("Invalid JSON data")

go
CopyEdit
105. ```bash
pip install requests
python
CopyEdit
import requests
response = [Link]('[Link]
print(response.status_code)

You might also like