Ask Question
Today, 13:06

1. We want to add a button to the tally counter in Section 9.2 that allows an operator to undo an accidental button click. Provide a method def undo (self) that simulates such a button. As an added precaution, make sure an undo doesn't cause the counter to be less than zero. 5 pts a) Your code with comments b) A screenshot of the execution Test Case: Reset 2 clicks Print Value 1 click Print Value 2 undos Print Value 2 undos Print Value

+5
Answers (1)
  1. Today, 14:52
    0
    See explaination

    Explanation:

    class Counter:

    def getValue (self):

    return self._value

    def undo (self):

    if self._value > 0:

    self._value = self._value - 1;

    def click (self):

    self._value = self._value + 1

    def reset (self):

    self._value = 0

    tally = Counter ()

    tally. reset ()

    tally. click ()

    tally. click ()

    result = tally. getValue ()

    print ("Value:", result)

    tally. click ()

    result = tally. getValue ()

    print ("Value:", result)

    tally. undo ()

    tally. undo ()

    result = tally. getValue ()

    print ("Value:", result)

    tally. undo ()

    tally. undo ()

    result = tally. getValue ()

    print ("Value:", result)
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “1. We want to add a button to the tally counter in Section 9.2 that allows an operator to undo an accidental button click. Provide a method ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers