Fall 2026
  • Discord
  • Gradescope
  • Syllabus

On this page

  • Start
  • Accounts and posts
  • Check and submit

Lab: A Social Media Feed

Due: Wednesday, October 28 at 11:59pm · Worth: 6 points

Classes let us keep data together with the methods that use it. You’ll build a social media feed with two kinds of objects. Each account keeps its own follower count, and each post keeps its own text and likes.

Start

Download and extract the starter ZIP. Open the inner lab-objects folder in VS Code, then initialize and publish your repository as lab-objects. Open lab_classes.py and feed_demo.py. Pick at least two account names; your feed can be about whatever you like.

Accounts and posts

Implement the methods in lab_classes.py. Store the like count on the post it belongs to, so liking one post leaves the others alone. For each account, keep a follower count. Then use your classes in feed_demo.py to create accounts and posts.

Implement the classes

Complete User and Tweet in lab_classes.py. The classes reading explains constructors and methods. Keep the starter’s signatures and use its doctests to check each method.

  • Store the supplied username in User.username and initialize its follower count to zero.

  • Implement User.follow() and User.unfollow(), increasing or decreasing that instance’s count by one without going below zero.

  • Store a tweet’s author username and text, and initialize its likes to zero.

  • Implement Tweet.like() and Tweet.unlike(), changing that instance’s count by one without going below zero.

  • Return @alice from the string representation of that user, and @alice: hello world from that tweet.

  • Compare users by username, regardless of follower counts. Different usernames and comparisons with non-users must be unequal.

  • Return hashtags from whitespace-separated words starting with #, removing only the first #. Preserve order, duplicates, capitalization, and punctuation. A lone # gives an empty string.

Build the feed

Complete the two functions in feed_demo.py using your own community and messages.

  • In build_feed(), create at least two distinct users and three distinct posts with nonempty names/text. Every author must be one of those usernames, each user must author a post, and at least one post must contain a nonempty hashtag. Return users, posts.

  • Call follow, unfollow, like, and unlike at least once on objects in the returned lists.

  • In main(), call build_feed() and print every returned user, post, and post’s hashtag list. Use the returned objects so another feed also displays correctly.

Check and submit

Run:

python -m doctest lab_classes.py
python feed_demo.py

Check that counters stop at zero and that changing one object does not change another. Add a post and confirm that the demonstration displays it and its hashtags.

Commit and sync lab_classes.py and feed_demo.py. On Gradescope, choose GitHub and submit lab-objects and the branch containing your work. The submission guide explains resubmission.