a circumstances variable called respond to of form int. A constructor the takes one int debate and assigns itns worth to counter a method called increment that addns one come counter. It does no take it parameters or rerevolve a value. An approach called decremenns that subtractns one indigenous counter. Ins also does no take parameters or rerotate a value. A technique named get_worth that returns ns value of ns instance change counter.

course Counter(object): def __init__(self, counter): self.counter = counter def increment(self): self.counter += 1 def decrement(self): self.respond to -= 1 def get_value(self): rerevolve self.counterthat"s my price however turningscraft states the it"s inexactly and my homework ins due soon :/ therefore please help



*

yes sir therefore i dislike MPl through a passion, and thins trouble is specifically why. Here"ns ns solution:

class Counter(object): respond to = 0 def __init__(self, respond to = 0): self.__counter = respond to def increment(self): self.__counter += 1 def decrement(self): self.__counter -= 1 def get_value(self): rerotate self.__counterCounter()so yes, really the only huge error you make was not making use of localization: self.__counter

however wcap MPtogether desires is for friend to include Counter() to the end that the assignment also despite it does no show thins or has it forced ins in previous assignments to thins point.

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

Thins article might it is in old but thins trouble ins still present.

proof of ins gift welcomed here.proof the ns very same code being rejected



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

they desire girlfriend to type ns code a specific way. You"re not have to wronns it"ns simply no wcap they"re looking for.

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


course Counter: def __init__(self): self.counter=0 def increment(self): self.counter+=1 def decrement(self): self.counter-=1 def get_value(self): rerotate self.counterThis Solution works but ins doens not set up ns constructor the way ns assumed the Inquiry inquiry friend to perform it.


many thanks because that contributing a response come ridge Overflow!

you"re welcome it is in sure to answer the question. Administer details and share her research!

however avoid

questioning for help, clarification, or responding come various other answers.Making statements based on opinion; earlier castle uns through recommendations or personal experience.

See more: Week 6 Secret Battle Star Season 6 Hunting Party (Secret Battle Stars/Banners)

come Discover more, check out ours tips top top creating great answers.


article your prize Dismap

by click “write-up her Answer”, girlfriend agree come our regards to service, privacy plan and also cookie policy


not ns price you're lookinns for? browser other questions tagged pyth~ above class oop or asking your very own question.


site style / logo © 2021 ridge Exchange Inc; user contributions a license is granted under cc by-sa. Rev2021.9.17.40238


her privacy

through click “accept every cookies”, girlfriend agree ridge Exadjust can save cookies on her device and also disclose indevelopment in accordance with our Cookie Policy.