exam questions

Exam PCEP-30-02 All Questions

View all questions & answers for the PCEP-30-02 exam

Exam PCEP-30-02 topic 2 question 88 discussion

Actual exam question from Python Institute's PCEP-30-02
Question #: 10
Topic #: 2
[All PCEP-30-02 Questions]

What is the output of the following code?

  • A. The output cannot be predicted.
  • B. 2
  • C. The program will cause an error.
  • D. 1
Show Suggested Answer Hide Answer
Suggested Answer: B 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
hovnival
1 month, 1 week ago
Selected Answer: B
1. `a` is assigned the value `1`. 2. `b` is assigned the value `0`. Next, we evaluate the expression `x = a or b`: - The `or` operator returns the first truthy value it encounters, or the last value if none are truthy. - `a` is `1`, which is truthy, so `x` will be `1`. Then, we evaluate the expression `y = not(a and b)`: - The `and` operator returns the first falsy value it encounters, or the last value if none are falsy. - `a` is `1` (truthy) and `b` is `0` (falsy), so `a and b` is `0`. - Applying the `not` operator to `0` (falsy) results in `True`, which is equivalent to `1` in Python. Finally, we compute `x + y`: - `x` is `1` and `y` is `1`. - So, `x + y` is `1 + 1`, which equals `2`. Therefore, the output of the code is: 2
upvoted 2 times
...
christostz03
5 months, 2 weeks ago
b is the correct answer 1 or 0 and not(a and b)= = 1 and 1 = =2
upvoted 1 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago