Skip to the content.

Unit 5 Lesson HACKS • 3 min read

Description

Hacks for APCSA Unit 5

Hacks

5.1-5.3 Hacks

POPCORN HACKS: 0.2

Create a simple To-Do List that utilizes the following (0.8):

  1. Private and Public Declaration

  2. Constructor

  3. Mutable Array containing To-Do List Items

Make sure to add descriptive comments that are describing your code!

class ToDoList:
    def __init__(self):
        # Private variable to store To-Do list items
        self._items = []
    def add_item(self, item):
        ///Public method to add an item to the To-Do list.
        // Args: item (str): The item to be added to the list.
        self._items.append(item)
    def remove_item(self, item):
        // Public method to remove an item from the To-Do list.
        // Args: item (str): The item to be removed from the list.
        if item in self._items:
            self._items.remove(item)
        else:
            print(f"{item} is not in the To-Do list.")    
    def display_list(self):
        // Public method to display the current To-Do list.

        print("To-Do List:")
        for i, item in enumerate(self._items, 1):
            print(f"{i}. {item}")
if __name__ == "__main__":
    # Create a To-Do list object
    my_todo_list = ToDoList()
    # Add items to the To-Do list
    my_todo_list.add_item("Buy groceries")
    my_todo_list.add_item("Finish homework")
    my_todo_list.add_item("Go to the gym")
    # Display the To-Do list
    my_todo_list.display_list()

    # Remove an item from the To-Do list
    my_todo_list.remove_item("Finish homework")

    # Display the updated To-Do list
    my_todo_list.display_list()

5.9-5.10 Hacks

POPCORN HACKS: 0.2

Write a two sentence reflection on the social and ethical implications of programming. (0.8)