0% found this document useful (0 votes)
4 views2 pages

Python code for setting goals

The document defines a task management system with classes for tasks and daily goals. Users can create daily goals, add tasks with deadlines, view tasks, and mark them as completed. The program runs in a loop allowing users to interactively manage their tasks until they choose to exit.

Uploaded by

Dante Dronzer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Python code for setting goals

The document defines a task management system with classes for tasks and daily goals. Users can create daily goals, add tasks with deadlines, view tasks, and mark them as completed. The program runs in a loop allowing users to interactively manage their tasks until they choose to exit.

Uploaded by

Dante Dronzer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import datetime

# Define a class to represent a task


class Task:
def __init__(self, description, deadline):
self.description = description
self.deadline = deadline
self.completed = False

def mark_completed(self):
self.completed = True

# Define a class to represent a daily goal


class DailyGoal:
def __init__(self, date):
self.date = date
self.tasks = []

def add_task(self, task):


self.tasks.append(task)

def list_tasks(self):
for idx, task in enumerate(self.tasks):
status = "Done" if task.completed else "Pending"
print(f"{idx + 1}. {task.description} - {task.deadline.strftime('%H:
%M')} - {status}")

def mark_task_completed(self, task_index):


if 0 <= task_index < len(self.tasks):
self.tasks[task_index].mark_completed()

# Function to create a new daily goal


def create_daily_goal():
today = datetime.date.today()
goal = DailyGoal(today)
return goal

# Function to add a new task to a goal


def add_task_to_goal(goal):
description = input("Enter task description: ")
deadline_str = input("Enter task deadline (HH:MM): ")
deadline = datetime.datetime.strptime(deadline_str, "%H:%M").time()
task = Task(description, deadline)
goal.add_task(task)

# Function to mark a task as completed


def complete_task(goal):
goal.list_tasks()
task_index = int(input("Enter the number of the task you completed: ")) - 1
goal.mark_task_completed(task_index)

# Main function to drive the program


def main():
goal = create_daily_goal()
while True:
print("\n1. Add a task")
print("2. View tasks")
print("3. Complete a task")
print("4. Exit")
choice = input("Choose an option: ")

if choice == "1":
add_task_to_goal(goal)
elif choice == "2":
goal.list_tasks()
elif choice == "3":
complete_task(goal)
elif choice == "4":
break
else:
print("Invalid choice. Please try again.")

if __name__ == "__main__":
main()

You might also like