exam questions

Exam PCEP-30-02 All Questions

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

Exam PCEP-30-02 topic 4 question 16 discussion

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

What is the expected behavior of the following snippet?

It will:

  • A. cause a runtime exception on Line 9
  • B. cause a runtime exception on Line 8
  • C. print 6
  • D. print 4
  • E. print 8
Show Suggested Answer Hide Answer
Suggested Answer: E 🗳️

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
Donny_575
3 weeks, 4 days ago
Selected Answer: E
E. Explanation: Line 1: x = 1 >>>Sets x to 1. Line 4–5: Defines function a(x) >>The function a(x) takes a value and returns 2 * x. Line 8: x = 2 + a(x) >>> At this point, x is 1 (from Line 1). So a(x) becomes a(1) → 2 * 1 = 2. >>> Now x = 2 + 2 = 4. So now x = 4. Line 9: print(a(x)) >>> Now we call a(4) → 2 * 4 = 8. So the output is 8
upvoted 1 times
...
akumo
1 month ago
Selected Answer: E
The output is 8 because after the value of x is updated to 4, the function a(x) is called with x = 4, and it returns 8.
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