PCEP Computer Programming and Python Fundamentals Practice Question
A script uses 'import math' then calls 'math.sqrt(-1)'. What is the outcome?
⚠ Common exam trap
The trap here is that candidates mistakenly think `math.sqrt()` can handle negative numbers by returning a complex number or NaN, confusing it with `cmath.sqrt()` or the behavior of some other languages' math libraries.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
ValueError
`math.sqrt()` in Python's math module does not support negative arguments; it raises a `ValueError` when given a negative number, as the function is designed for real numbers only. The error message is 'math domain error', indicating the input is outside the domain of the mathematical function.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
ValueError
Why this is correct
math domain error because sqrt of negative number is not defined in real math.
- ✗
NaN
Why it's wrong here
math.sqrt does not return NaN; it raises an error.
- ✗
A complex number
Why it's wrong here
math.sqrt does not return complex; use cmath for complex numbers.
- ✗
AttributeError
Why it's wrong here
The attribute sqrt exists; the error is in the argument.
Go deeper
Related to this question
About these practice questions
One of 498 original PCEP practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This PCEP practice question is part of Courseiva's free Python Institute certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCEP exam.