Counting the days posted in a row
Write code · Challenge · §11.6 The math helper evolves
Write a class StreakTracker that remembers whether you posted each day and counts how many days in a row you posted. When you create one with StreakTracker(), its attributes start like this: last (the last day you posted) is None, streak (the current number of days in a row) is 0, and best (the longest streak so far) is 0.
post(day) receives the number of a day you posted (1, 2, 3, …). Day numbers never go down. Posting twice on the same day counts as once. If day is the day right after the last day you posted, add 1 to streak. If you skipped even one day, or if this is your first post, start streak again at 1. best is the largest streak so far.
Starter code
class StreakTracker:
# Write __init__ and post here
pass
t = StreakTracker()
for day in [1, 2, 3, 5, 6]:
t.post(day)
print(t.last, t.streak, t.best)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.