exam questions

Exam PCEP-30-02 All Questions

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

Exam PCEP-30-02 topic 1 question 51 discussion

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

What is the expected output of the following code?

  • A. 0
  • B. 1
  • C. The code is erroneous.
  • D. 2
Show Suggested Answer Hide Answer
Suggested Answer: A 🗳️

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
2 days, 10 hours ago
Selected Answer: A
Let's go through the code step by step: The dictionary data is defined as {1: 0, 2: 1, 3: 2, 0: 1}. The variable x is initialized to 0. The for loop runs len(data) times, which is 4 times since the length of the dictionary data is 4. Let's trace the value of x through each iteration of the loop: Iteration 1: x = data[0] which is 1. So x becomes 1. Iteration 2: x = data[1] which is 0. So x becomes 0. Iteration 3: x = data[0] which is 1. So x becomes 1. Iteration 4: x = data[1] which is 0. So x becomes 0. After completing the loop, the value of x is 0. Therefore, the output is: 0
upvoted 1 times
...
christostz03
4 months, 1 week ago
a is the correct answer
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