LearnFrenzy
Sign in Take a free test

Modules and Packages · Exercise 2 of 4

Modules and Packages Predict the Output

  • 15 questions
  • Page 2 of 2
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Read each Python program and choose what it prints. Every program was run on Python 3, so the answers are the real output. Programs that need their own module create it in a temporary folder first.

Question 11 Medium

What is the output of the following Python program?

main.py
from pathlib import PurePosixPath as P

p = P("data") / "2026" / "marks.final.csv"
print(p, p.suffix, p.stem, p.parent, p.name)
A data/2026/marks.final.csv .final.csv marks data/2026 marks.final.csv
B data\2026\marks.final.csv .csv marks.final data marks
C data/2026/marks.final.csv csv marks data/2026 marks.final
D data/2026/marks.final.csv .csv marks.final data/2026 marks.final.csv
Question page & discussion
Question 12 Hard

What is the output of the following Python program?

main.py
import sys, tempfile, pathlib

folder = pathlib.Path(tempfile.mkdtemp())
(folder / "lf_util.py").write_text(
    '__all__ = ["public"]\n'
    'def public(): return "public"\n'
    'def helper(): return "helper"\n'
    'def _hidden(): return "hidden"\n')
sys.path.insert(0, str(folder))

from lf_util import *
print("public" in dir(), "helper" in dir(), "_hidden" in dir())
A True True False
B True True True
C False False False
D True False False
Question page & discussion
Question 13 Hard

What is the output of the following Python program?

main.py
import sys, tempfile, pathlib, importlib

folder = pathlib.Path(tempfile.mkdtemp())
(folder / "lf_banner.py").write_text('print("loading")\n')
sys.path.insert(0, str(folder))

import lf_banner
import lf_banner
print("imported twice")
importlib.reload(lf_banner)
A loading loading imported twice loading
B loading imported twice
C imported twice loading
D loading imported twice loading
Question page & discussion
Question 14 Medium

What is the output of the following Python program?

main.py
import sys, tempfile, pathlib

folder = pathlib.Path(tempfile.mkdtemp())
(folder / "lf_helper.py").write_text(
    'if __name__ == "__main__":\n    print("run as a script")\n'
    'else:\n    print("imported as", __name__)\n')
sys.path.insert(0, str(folder))

import lf_helper
print("main program:", __name__)
A run as a script main program: __main__
B imported as lf_helper main program: __main__
C imported as __main__ main program: __main__
D main program: __main__
Question page & discussion
Question 15 Easy

What is the output of the following Python program?

main.py
import statistics as st
print(st.mean([1, 2, 3, 4]), st.median([3, 1, 2]), st.median([4, 1, 3, 2]), st.mode([1, 1, 2]))
A 2.5 1 2.5 1
B 2 2 2 1
C 2.5 2 2.5 1
D 2.5 2 3 2
Question page & discussion
Up next · Exercise 3Find the Error10 questions

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links