📢 Too many exams? Don’t know which one suits you best? Book Your Free Expert 👉 call Now!


    Question

    Given the following Python-like code snippet: 

       ```python     class Counter:         def __init__(self):             self.count = 0         def increment(self):             self.count += 1         def get_count(self):             return self.count     c1 = Counter()     c2 = Counter()     c1.increment()     c1.increment()     c2.increment()     print(c1.get_count() + c2.get_count())     ```     What will be the output?
    A 1 Correct Answer Incorrect Answer
    B 2 Correct Answer Incorrect Answer
    C 3 Correct Answer Incorrect Answer
    D 4 Correct Answer Incorrect Answer

    Solution

    Dry Run:            `c1 = Counter()` -> `c1.count = 0`            `c2 = Counter()` -> `c2.count = 0`            `c1.increment()` -> `c1.count = 1`            `c1.increment()` -> `c1.count = 2`            `c2.increment()` -> `c2.count = 1`            `print(c1.get_count() + c2.get_count())` -> `print(2 + 1)` -> `3`

    Practice Next
    ask-question