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

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

What is the expected output of the following code?

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

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
4 days, 10 hours ago
Selected Answer: D
The code will raise a TypeError. Here's the explanation: The tuple data = (1,) * 3 creates a tuple containing three elements: (1, 1, 1). Tuples in Python are immutable, meaning their elements cannot be modified after creation. The statement data[0] = 2 attempts to modify the first element of the tuple, which is not allowed. Because of the immutability of tuples, attempting to modify an element will result in a TypeError. Thus, the expected output is an error message similar to: TypeError: 'tuple' object does not support item assignment
upvoted 1 times
...
FedeXD
3 months, 2 weeks ago
Tuples are immutable, therefore you can't modify its elements.
upvoted 4 times
...
imran04120
4 months ago
TypeError: 'tuple' object does not support item assignment If it was a list then it would be [2,1,1]
upvoted 2 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