exam questions

Exam PCAP-31-03 All Questions

View all questions & answers for the PCAP-31-03 exam

Exam PCAP-31-03 topic 1 question 76 discussion

Actual exam question from Python Institute's PCAP-31-03
Question #: 76
Topic #: 1
[All PCAP-31-03 Questions]

Which of the following lines of code will work flawlessly when put independently inside the inc() method in order to make the snippet's output equal to 3? (Choose two.)

  • A. put(self.prop + val)
  • B. self.put(self.prop + val)
  • C. self.put(self.get() + val)
  • D. self.put(get() + val)
Show Suggested Answer Hide Answer
Suggested Answer: BC 🗳️

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
flthymcnsty
4 months, 3 weeks ago
Selected Answer: BC
Explanation: Step-by-Step Breakdown: Initialization: When Object = MyClass() is created, the __init__ method increments MyClass.Var to 1 and sets self.prop = 1. Object.inc(2): The inc() method takes val as an argument, and one of the provided options will be inserted to modify self.prop to 3. print(Object.get()): Calls Object.get() to return self.prop. To get the output 3, the inc() method must increment self.prop by val (2 in this case). The correct answers are: B. self.put(self.prop + val) self.put() is a method of MyClass that updates self.prop. self.prop + val calculates 1 + 2 = 3 and assigns it to self.prop. C. self.put(self.get() + val) self.get() returns the current value of self.prop, which is 1. self.get() + val calculates 1 + 2 = 3. self.put(3) assigns 3 to self.prop.
upvoted 3 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