nerdexam
Python_Institute

PCEP-30-02 · Question #297

PCEP-30-02 Question #297: Real Exam Question with Answer & Explanation

Sign in or unlock PCEP-30-02 to reveal the answer and full explanation for question #297. The question stem and answer options stay visible for context.

Question

Analyze the following code fragments that assign a boolean value to the variable even? Code-1:
1 num = 42
2
3 # Code-1
4 if num % 2 == 0:
5 even = True
6 else:
7 even = False
Code-2:
9 # Code-2
10 even = True if num % 2 == 0 else False
Code-3:
12 # Code-3
13 even = num % 2 == 0

Options

  • AAll three are correct, but Code-2 is preferred.
  • BAll three are correct, but Code-3 is preferred.
  • CCode-3 has a syntax error because you attempt to assign a number to even.
  • DAll three are correct, but Code-1 is preferred.
  • ECode-2 has a syntax error because you cannot have True and False literals in the conditional expression.

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.

Full PCEP-30-02 Practice