LearnFrenzy
Sign in Take a free test

Modules and Packages · Exercise 4 of 4

Modules and Packages Modules and Packages Coding Problems

  • 10 questions
  • Page 1 of 1
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Python programs that create and use modules and packages, and put the standard library to work. Write each one yourself first, then open the solution – every solution was run on Python 3, the output shown is the real output, and Run opens it in the online Python compiler.

Question 1 Easy

Write a module lf_marks.py with average() and grade() functions and a __main__ guard, then import it and use it. (The program writes the module to a temporary folder so it runs as one file.)

Question page & discussion
Question 2 Medium

Create a package lf_units with modules length.py and weight.py, re-export their functions in __init__.py, and use them through the package.

Question page & discussion
Question 3 Easy

For a fixed "today" of 30 Nov 2026, print how many days and weeks remain until each exam, and the weekday of each exam.

Question page & discussion
Question 4 Easy

Use Counter to find the 3 most common words of a paragraph, the number of distinct words, and the words used exactly once.

Question page & discussion
Question 5 Medium

For four teams, list every match of a single round-robin with combinations, count home-and-away fixtures with permutations, and the number of 2-member squads from 6 players.

Question page & discussion
Question 6 Medium

Convert a list of student dicts to JSON text, write it to a temporary file, read it back, and print the topper and the JSON of the first record.

Question page & discussion
Question 7 Easy

Use math to compute the hypotenuse of a right triangle, the area of a circle, the angle of a ramp in degrees, and the distance between two points.

Question page & discussion
Question 8 Medium

List the public callables of the statistics module whose names contain "mean", and show the first line of one function's docstring.

Question page & discussion
Question 9 Hard

Create two folders, each containing a module lf_shared.py with a different VERSION. Show that the folder earlier in sys.path wins, and print which file was loaded.

Question page & discussion
Question 10 Medium

Try to import a fast third-party JSON library (lf_fastjson, not installed); fall back to the standard json module, and report which one is used.

Question page & discussion
All exercises doneBack to Modules and PackagesRevise the concepts or pick another topic

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links