A school shop has two different files named pricing.py. Their complete contents are shown below.
File /class/shop/pricing.py
UNIT_PRICE = 275
File /class/shared/pricing.py
UNIT_PRICE = 240
Both prices are in cents per notebook. The module search path is the ordered list of folders Python searches to locate a module. Here, sys.path.insert(0, folder) places the specified folder at the beginning of that list.
The following program runs once in a fresh Python interpreter. Neither file has previously been imported, both folders are accessible, and no other pricing module takes precedence. The program does not reload modules or remove previously loaded modules.
import sys sys.path.insert(0, "/class/shared") sys.path.insert(0, "/class/shop") import pricing first_total = 8 * pricing.UNIT_PRICE sys.path.insert(0, "/class/shared") import pricing as later_pricing second_total = 12 * later_pricing.UNIT_PRICE
Find first_total and second_total. Enter each total in cents, to zero decimal places.
Unlock full course notes by signing up
Track the names an import introduces
Each Python statement below runs separately in a fresh session. Enter the single name that the statement makes directly available for later use. Enter only the name, without parentheses or a dotted expression.
Calculate with two import forms
An art supplier can divide 37.5 kg of clay among cartons, each holding at most 8.0 kg. The following Python code calculates packing quantities. Here floor rounds down to an integer and ceil rounds up to an integer.
Find full, the number of completely filled cartons, and cartons, the total number needed, as exact integers. Find unused, the total unused capacity in kg, to one decimal place. Ignore carton mass and packing losses.
Locate the cause of an import-related error
A packing application can successfully import a local file named supplies.py, which contains only this assignment:
No module named missing_supplies is available. Each snippet below runs separately in a fresh Python interpreter. Enter the exception class raised by each snippet: ModuleNotFoundError, ImportError, or AttributeError.
Snippet A
Separate an imported value from a module attribute
A project contains a Python module named local_rates.py whose entire contents are shown below:
In a fresh session, a booking program then runs this code successfully:
Which statements are true immediately afterward? Select every true statement. Assume no other imports or assignments occur.