← Back

Home β€Ί Problems β€Ί ModuleNotFoundError: no module 'maths'

ModuleNotFoundError: no module 'maths'

πŸ› Fix the bug Topic: exceptions Difficulty: medium Free

What this problem practises

Exceptions are control flow. except clauses are matched top to bottom, finally runs even after a return, and catching too broadly hides the real bug behind a generic message.

This is a fix-the-bug problem: a short program is given in its broken state, and the task is to repair the code so it produces the required output. The interactive editor runs your fixed version in the browser and checks it for you β€” no setup, no local interpreter.

Difficulty: medium β€” expect to hold two interacting rules in your head at once, such as a boundary combined with a mutation.

The challenge

This program crashes with ModuleNotFoundError because the module name is misspelled. Fix the import so it prints 6.0.

The code runs in PyDebug’s in-browser compiler. Open the problem, run the snippet, watch the exact error or output, and keep iterating until it is right. Signed-in solves count toward XP and your daily streak.

The error it raises

Run the broken snippet and Python stops with this exact error: ModuleNotFoundError: No module named 'maths'. Match it to the Python errors guide, then repair the line that produced it β€” knowing the message is half the fix.

The snippet

The interactive editor pre-fills exactly this code, broken and ready to repair:

import maths
print(maths.sqrt(36))

Understand the rule

Learners in British and Indian English curricula naturally type `import maths`, only to hit `ModuleNotFoundError: No module named 'maths'` on line 1. Python's standard-library math module uses the singular American spelling `math` (`import math`).

How to trace it

  1. When Python executes `import maths`, the import system searches `sys.modules`, built-in modules, and every directory on `sys.path`.
  2. Standard library ships `math` (and `cmath` for complex numbers), so no file or built-in named `maths` is found.
  3. Because `ModuleNotFoundError` (a subclass of `ImportError`) is raised at import time, none of the calculations below line 1 execute.
  4. Updating both the `import math` statement and any `maths.sqrt(...)` / `maths.pi` prefixes to `math.` resolves the failure cleanly.

Common wrong fixes

Rule to remember

Python's built-in module is always singular `math` β€” update both the `import` line and every `math.<func>` reference.

Solve it in the interactive editor β†’

More exceptions problems

Keep going