An instance variable called respond to of form int. A constructor that takes one int debate and assigns its value to respond to A technique called increment that adds one to respond to. It does not take parameters or return a worth. A method named decrement that subtracts one from counter. It also does not take parameters or return a value. A method named get_value that returns the value of the instance variable respond to.

course Counter(object): def __init__(self, counter): self.respond to = respond to def increment(self): self.respond to += 1 def decrement(self): self.counter -= 1 def get_value(self): rerotate self.counterthat"s my answer yet turningscraft claims that it"s incorrect and also my homework is due shortly :/ so please help


*

*

Ok so I hate MPL via a passion, and this trouble is specifically why. Here"s the solution:

course Counter(object): respond to = 0 def __init__(self, counter = 0): self.__counter = respond to def increment(self): self.__respond to += 1 def decrement(self): self.__respond to -= 1 def get_value(self): rerotate self.__counterCounter()So really the only huge error you made was not making use of localization: self.__counter

But what MPL desires is for you to add Counter() to the end of the assignment even though it does not indicate this or has actually it compelled it in previous assignments to this point.

You are watching: Write the definition of a class counter containing

This article might be old but this difficulty is still existing.

Proof of it being welcomed below.Proof of the same code being rejected


*

course Counter(object): def __init__(self): self.respond to = 0 def increment(self): self.respond to += 1 def decrement(self): self.respond to -= 1 def get_value(self): rerotate self.respond to
*

They desire you to form the code a certain method. You"re not necessarily wrong it"s just not what they"re trying to find.

class Counter: def __init__(self, counter=0): self.__respond to =respond to def increment(self): self.__counter +=1 def decrement(self): self.__counter -=1 def get_value(self): return self.__respond to

*

class Counter: def __init__(self): self.counter=0 def increment(self): self.counter+=1 def decrement(self): self.counter-=1 def get_value(self): rerevolve self.counterThis solution works yet it does not set up the constructor the means I assumed the question asked you to carry out it.


course Counter(): respond to = 0 def increment(self): self.respond to +=1 def decrement(self): self.respond to -=1 def get_value(self): return self.counterMPL is weird, and it didn"t desire the __init__


Thanks for contributing a response to Stack Overflow!

Please be certain to answer the question. Provide details and also share your research!

But avoid

Asking for aid, clarification, or responding to various other answers.Making statements based upon opinion; earlier them up with referrals or individual suffer.

See more: Distance Between Puerto Rico And Dominican Republic, Distance From Dominican Republic To Puerto Rico

To learn even more, see our tips on writing great answers.


Message Your Answer Discard

By clicking “Blog post Your Answer”, you agree to our terms of service, privacy policy and also cookie policy


Not the answer you're looking for? Browse various other concerns tagged python course oop or ask your very own question.


Site architecture / logo design © 2022 Stack Exadjust Inc; user contributions licensed under cc by-sa. rev2022.4.7.41894


Your privacy

By clicking “Accept all cookies”, you agree Stack Exadjust have the right to save cookies on your gadget and also disclose information in accordance through our Cookie Policy.