Python_Institute
PCEP-30-02 · Question #314
PCEP-30-02 Question #314: Real Exam Question with Answer & Explanation
Sign in or unlock PCEP-30-02 to reveal the answer and full explanation for question #314. The question stem and answer options stay visible for context.
Question
You are coding a math utility by using Python. You are writing a function to compute roots. The function must meet the following requirements:
- If a is non-negative, return a ** (1 / b)
- If a is negative and even, return 'Result is an imaginary number'
- If a is negative and odd, return -(a) ** (1 / b) Which of the following functions meets the requirements?
Options
- A
def safe_root(a, b): if a >= 0: answer = a ** (1 / b) elif a % 2 == 0: answer = 'Result is an imaginary number' else: answer = -(-a) ** (1 / b) return answer - B
def safe_root(a, b): if a >= 0: answer = a ** (1 / b) elif a % 2 == 0: answer = 'Result is an imaginary number' else: answer = -(a) ** (1 / b) return answer - C
def safe_root(a, b): if a % 2 == 0: answer = a ** (1 / b) elif a >= 0: answer = 'Result is an imaginary number' else: answer = -(-a) ** (1 / b) return answer - D
def safe_root(a, b): if a >= 0: answer = -(a) ** (1 / b) elif a % 2 == 0: answer = 'Result is an imaginary number' else: answer = a ** (1 / b) return answer
Unlock PCEP-30-02 to see the answer
You've previewed enough free PCEP-30-02 questions. Unlock PCEP-30-02 for full answers, explanations, the timed quiz mode, progress tracking, and the master PDF. Question stem and options stay visible so you can still see what's on the exam.