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 49 discussion

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

What is the expected output of the following code?

  • A. Paul
  • B. Mary
  • C. The code is erroneous.
  • D. None of the above.
  • E. Peter
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
hovnival
2 days, 19 hours ago
Selected Answer: E
The expression int(-1 / 2) prints Peter because of the way integer division and type conversion work in Python. Let's break it down step by step: Division Operation: When you perform the division -1 / 2, the result is -0.5. Type Conversion: The int function converts a floating-point number to an integer by truncating the decimal part. This means it removes the fractional part without rounding. Therefore, int(-0.5) becomes 0. List Indexing: In Python, list indexing starts from 0. So, data[0] refers to the first element of the list. Combining these steps, the expression data[int(-1 / 2)] is equivalent to data[0], which accesses the first element of the list data, which is 'Peter'. So, the reason (-1 / 2) prints 'Peter' is because the expression evaluates to 0, and data[0] refers to the first element of the list.
upvoted 1 times
...
christostz03
4 months, 1 week ago
e 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