Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
2.1 kB
1
Indexable
Never
class HabitTracker:
    def __init__(self):
        # Initialize an empty dictionary to store habits for each day
        self.habits = {
            'Monday': [],
            'Tuesday': [],
            'Wednesday': [],
            'Thursday': [],
            'Friday': [],
            'Saturday': [],
            'Sunday': []
        }

    def add_habit(self, day, habit):
        # Add a habit to the specified day
        self.habits[day].append(habit)
        print(f"{habit} added to {day}'s habits.")

    def remove_habit(self, day, habit):
        # Remove a habit from the specified day
        if habit in self.habits[day]:
            self.habits[day].remove(habit)
            print(f"{habit} removed from {day}'s habits.")
        else:
            print(f"{habit} not found in {day}'s habits.")

    def view_habits(self, day):
        # View habits for the specified day
        print(f"Habits for {day}:")
        if self.habits[day]:
            for habit in self.habits[day]:
                print(f"- {habit}")
        else:
            print("No habits for this day.")

# Example usage
habit_tracker = HabitTracker()

while True:
    print("\nHabit Tracker Menu:")
    print("1. Add Habit")
    print("2. Remove Habit")
    print("3. View Habits")
    print("4. Quit")

    choice = input("Enter your choice (1-4): ")

    if choice == '1':
        day = input("Enter the day of the week: ").capitalize()
        habit = input("Enter the habit to add: ")
        habit_tracker.add_habit(day, habit)
    elif choice == '2':
        day = input("Enter the day of the week: ").capitalize()
        habit = input("Enter the habit to remove: ")
        habit_tracker.remove_habit(day, habit)
    elif choice == '3':
        day = input("Enter the day of the week: ").capitalize()
        habit_tracker.view_habits(day)
    elif choice == '4':
        print("Exiting Habit Tracker. Goodbye!")
        break
    else:
        print("Invalid choice. Please enter a number between 1 and 4.")
Leave a Comment