HelpContactFor teachers and institutes
>_StemPy Lab
Mock TestsClasses

>_StemPy Lab

Learn. Solve. Code the solutions. Test yourself.

Live examsFree mock exams, timed and rankedEveryone starts together, and your score and rank come the moment it ends.See the exams →
Live examsInternational live exams are comingTell us which exam you want first. Timed practice papers are open now.See what is coming →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data Science
  • Computer Science
  • Space Science and Astronomy
  • Earth and Environmental Science
  • Classes
  • Groups

Practice

  • Problems
  • Quizzes
  • Mock Tests
  • Prepare for an Exam
  • Question Sets
  • Exams
  • Certificates
  • Python Labs
  • AI Practice Generator
  • Student-Created Tests

Community

  • Discussions
  • Resources
  • Notes
  • Glossary
  • Blog

Account

  • Log in
© 2026 senLearn. All rights reserved.HelpFor SchoolsAboutContactPrivacy PolicyTerms of UseRefund Policy
  1. Python Programming
  2. /Python Essentials
  3. /Modules and Libraries

Modules and Libraries

Python Programming · High School (9–10) · 1 course, 14 worked problems, 40 practice questions

No programmer writes everything from scratch. A module is a file of Python code that other programs can use, and a library is a collection of modules. You bring one in with import, for example import math, and then use math.sqrt() or math.pi. With from random import randint, you take just one name. The standard library comes with Python and includes math, random, statistics and datetime. Other libraries, such as NumPy and matplotlib, are installed separately. You can also write your own module of functions and import it into another program.

With practice you will be able to

  • Import a module and use its functions
  • Use math and random to solve small problems
  • Write your own module and import it into another program

On the syllabus of

  • CBSE / State Class 12
  • Python Certification
  • AP

Lessons

  • Import a Toolbox: ModulesHow many 45-seat buses do 130 students need? Is your die really fair?High School (9–10)

Practice questions

Choose an answer, then check it. Each one shows a full explanation.

A module geo.py holds a class. The program main.py, in the same folder, imports it in two ways. geo.py: class Point: made = 0 def __init__(self): Point.made += 1 main.py: import geo from geo import Point a = Point() b = geo.Point() print(Point.made, type(a).__module__, isinstance(b, Point)) What does main.py print?

Three files sit in one folder. The module settings.py makes one object when it is loaded. The module helper.py changes that object. You run main.py. settings.py: class Settings: def __init__(self): self.theme = "light" current = Settings() helper.py: import settings def go_dark(): settings.current.theme = "dark" main.py: import settings from settings import current import helper helper.go_dark() settings.current = settings.Settings() print(current.theme, settings.current.theme) What does main.py print?

The program main.py imports floor from math, and then everything from its own module tools.py. tools.py: from math import ceil def floor(x): return int(x) + 10 main.py: from math import floor from tools import * print(floor(2.7), ceil(2.1)) What does main.py print?

A module config.py holds a number and a class whose method uses that number. The program main.py imports both and then changes a variable called RATE in two places. config.py: RATE = 2 class Meter: def reading(self, n): return n * RATE main.py: import config from config import Meter, RATE m = Meter() RATE = 5 first = m.reading(3) config.RATE = 10 After this code, which of these expressions are True? Select all that apply.

One or more options are correct. Tick all the correct ones: a wrong option costs marks, and a part-right answer earns part of the marks.

A module calc.py and the program main.py sit in the same folder. The program imports the module inside a function. calc.py: def double(n): return n * 2 main.py: import sys def load(): import calc return calc.double(4) print(load(), "calc" in dir(), "calc" in sys.modules) What does main.py print?

A program asks the platform module which version of Python is running. It prints nothing. import platform v = platform.python_version() t = platform.python_version_tuple() Which expressions are True after this code, on any computer? Choose every correct option.

One or more options are correct. Tick all the correct ones: a wrong option costs marks, and a part-right answer earns part of the marks.

A program mixes the letters of a list with random.shuffle, then uses two more functions of random. import random letters = list("abcde") random.shuffle(letters) print(sorted(letters) == list("abcde"), len(set(random.sample(letters, 5))), random.randint(3, 3)) What does the program print, every time it runs?

A program imports math under a short name and works with three numbers read from a string. import math as m values = "9 16 25".split() roots = [m.sqrt(int(v)) for v in values] print(roots[0], m.ceil(roots[1] / 3), m.factorial(len(values))) What does the program print?

A module strtools.py and the program main.py sit in the same folder. The program lists the module's names with dir(). strtools.py: def shout(s): return _clean(s).upper() def _clean(s): return s.strip() VOWELS = "aeiou" main.py: import strtools names = [n for n in dir(strtools) if not n.startswith("__")] print(names, strtools.shout(" hey ")) What does main.py print?

The program is saved as main.py and run with the command python main.py, with nothing typed after it. import sys name = sys.argv[0] print(name, name.endswith(".py"), name[:-3].upper(), len(sys.argv)) What does the program print?

All 40 practice questions on Modules and Libraries →

Worked problems

Each one has a hint, the key idea and a full worked solution.

  • Find out, with dir and help, which function of math gives the sine of an angle, and which gives the…Easy
  • Which module would you use for each job? …Easy
  • Roll two dice 6000 times, with the seed 3…Medium
  • A shop sells these items on one day, with the prices [20, 25, 25, 30, 22, 28, 400]…Easy
  • Use the math module to find the square root of 144, and the area of a circle of radius 5 with A = π…Easy
  • A school trip has 130 students. Each bus has 45 seats. How many buses are needed?Medium
  • Find the long side (the hypotenuse) of a right triangle with the other sides 3 and 4, and with 5…Medium
  • Find 5!, the greatest common divisor of 12 and 18, and the greatest common divisor of 17 and 5.Easy
  • Pick a winner at random from ["Asha", "Ravi", "Meera", "Kabir"].Easy
  • A list of the numbers 1 to 8 is shuffled with random.shuffle…Medium
  • Find the mean, the median and the mode of 4, 8, 6, 5, 3, 8, 9.Medium
  • How many days are there from 11 October 2026 to 25 December 2026?Medium

All 14 worked problems on Modules and Libraries →

Python labs

  • Use the math tools
  • Roll and count
  • Describe the data
  • List the tools
  • Project: the dice laboratory
  • A table of tools

Related topics

  • Python Essentials
  • Dictionaries
  • Tuples and Sets
  • Errors and Exceptions
  • Searching and Sorting
  • Recursion
  • Text Processing
  • Essentials Projects