A follower count that never goes down
Code review · Basic · §11.2, §11.3 Methods that change state
This class counts followers. It runs without errors, but after three follows and one unfollow, it prints sora 3. Fix one line so that it prints sora 2. Grading also calls the methods in other orders.
Code to fix
class Followers:
def __init__(self, name):
self.name = name
self.count = 0
def follow(self):
self.count += 1
def unfollow(self):
if self.count > 0:
count = self.count - 1
def get(self):
return self.count
f = Followers("sora")
f.follow()
f.follow()
f.follow()
f.unfollow()
print(f.name, f.get())Solve this problem in your browser
Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.