What a library is: standard vs third-party

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

What a library is: standard vs third-party

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. What is a library in Python?
A A collection of ready-made code you can reuse
B A program that only runs in a web browser
2. Which library comes with Python when you install it?
A random (standard library)
B requests (standard library)
3. A third-party library is...
A Built into Python and always available
B Made by others and installed separately, e.g. with pip
4. Which statement is correct?
A import math works without installing anything
B import math needs pip install math first
5. What is the main benefit of using a library?
A You must rewrite every function yourself
B Reusing tested code saves time and effort

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1import random ALoads a standard library module that ships with Python, so no installation is needed
2pip install requests Bpip install pandas
3The standard library is a collection of ready-made code that comes with Python and needs no installation Cimport math
4A third-party library is made by others and must be installed separately before you can reuse its code DInstalls a third-party library made by others so it can be imported into your program
5pip install random import random Erandom is part of the standard library, so it already comes with Python and does not need to be installed with pip.
6import requests (never installed) Frequests is a third-party library. Importing it without installing it first with pip causes a ModuleNotFoundError.

Definitions

library

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
______ math print(math.sqrt(25))
2.
import ______ print(random.randint(1, 6))
3.
___ install requests
4.
from math import ____ print(sqrt(49))
5.
import ________ today = datetime.date.today()

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A import random
B names = ['Ava', 'Liam', 'Mia']
C count = len(names)
D winner = random.pick(names)
E print(winner)
Question 2
A import math
B r = 5
C area = pi * r ** 2
D print(area)
Question 3
A import random
B dice = Random.randint(1, 6)
C print(dice)
Question 4
A import numpy as np
B marks = np.array([70, 85, 90])
C avg = numpy.mean(marks)
D print(avg)
Question 5
A from datetime import date
B today = datetime.today()
C print(today.year)

Answer Key

What a library is: standard vs third-party
Section A: Quick Questions
Q1
A — A collection of ready-made code you can reuse
Q2
A — random (standard library)
Q3
B — Made by others and installed separately, e.g. with pip
Q4
A — import math works without installing anything
Q5
B — Reusing tested code saves time and effort
Section B: Match the Pairs
Q1
import random → Loads a standard library module that ships with Python, so no installation is needed
Q2
pip install requests → Installs a third-party library made by others so it can be imported into your program
Q3
The standard library is a collection of ready-made code that comes with Python and needs no installation → import math
Q4
A third-party library is made by others and must be installed separately before you can reuse its code → pip install pandas
Q5
pip install random import random → random is part of the standard library, so it already comes with Python and does not need to be installed with pip.
Q6
import requests (never installed) → requests is a third-party library. Importing it without installing it first with pip causes a ModuleNotFoundError.
Section C: Definitions
Q1
library — A collection of ready-made code you can reuse. The standard library comes with Python; third-party libraries are made by others and must be installed separately (e.g. with pip).
Section D: Fill in the Blanks
Q1
import math print(math.sqrt(25))
Q2
import random print(random.randint(1, 6))
Q3
pip install requests
Q4
from math import sqrt print(sqrt(49))
Q5
import datetime today = datetime.date.today()
Section E: Spot the Error
Q1
D — The random module is part of the standard library, but it has no function called pick(). The function that chooses an item from a list is random.choice(names).
Q2
C — The program uses import math, so pi must be accessed through the module as math.pi. Writing pi on its own causes a NameError. It should be area = math.pi * r ** 2.
Q3
B — Python is case-sensitive and the standard library module is named random in lowercase. Random is not defined. It should be dice = random.randint(1, 6).
Q4
C — numpy is a third-party library that was imported with the alias np, so the name numpy is not defined in this program. It should be avg = np.mean(marks).
Q5
B — Only date was imported from the standard library datetime module, so the name datetime does not exist here. It should be today = date.today().