Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jun 29, 2024. It is now read-only.

Commit f1cfe28

Browse files
to_dolist
1 parent e71258e commit f1cfe28

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

‎thattururajitha/to_dolist‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,41 @@
1+
# Define a class to represent a to-do list
12
class ToDoList:
3+
# Initialize the ToDoList with an empty list of tasks
24
def __init__(self):
35
self.tasks = []
46

7+
# Add a task to the list
58
def add_task(self, task):
69
self.tasks.append(task)
710
print(f"Task '{task}' added successfully!")
811

12+
# Delete a task from the list if it exists
913
def delete_task(self, task):
1014
if task in self.tasks:
1115
self.tasks.remove(task)
1216
print(f"Task '{task}' deleted successfully!")
1317
else:
1418
print(f"Task '{task}' not found.")
1519

20+
# Mark a task as completed if it exists
1621
def mark_completed(self, task):
1722
if task in self.tasks:
1823
print(f"Task '{task}' marked as completed!")
1924
else:
2025
print(f"Task '{task}' not found.")
2126

27+
# Display all the tasks in the list
2228
def display_tasks(self):
2329
print("\nCurrent tasks:")
2430
for i, task in enumerate(self.tasks, start=1):
2531
print(f"{i}. {task}")
2632

33+
# Define the main function that will run the to-do list application
2734
def main():
35+
# Create an instance of the ToDoList class
2836
todo = ToDoList()
2937

38+
# Loop to display the menu and process user input
3039
while True:
3140
print("\nMenu:")
3241
print("1. Add Task")
@@ -35,8 +44,10 @@ def main():
3544
print("4. Display Tasks")
3645
print("5. Exit")
3746

47+
# Get the user's choice
3848
choice = input("Enter your choice (1/2/3/4/5): ")
3949

50+
# Process the user's choice and call the appropriate method
4051
if choice == '1':
4152
task = input("Enter the task: ")
4253
todo.add_task(task)
@@ -49,10 +60,14 @@ def main():
4960
elif choice == '4':
5061
todo.display_tasks()
5162
elif choice == '5':
63+
# Exit the application
5264
print("Exiting the application. Have a great day!")
5365
break
5466
else:
67+
# Handle invalid choices
5568
print("Invalid choice. Please select a valid option.")
5669

70+
# Check if the script is being run directly and not imported
5771
if __name__ == "__main__":
72+
# If the script is run directly, call the main function to start the application
5873
main()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /