Project Overview
Is project me hum ek simple To-Do List App banayenge. User apne tasks add, dekh aur delete kar paayega. Hum functions, lists, loops, conditions aur file I/O ka use karenge.
Step 1: Basic Structure
tasks = []
def show_menu():
print("\n=== To-Do List App ===")
print("1. Add Task")
print("2. View Tasks")
print("3. Delete Task")
print("4. Save & Exit")
Step 2: Adding a Task
def add_task():
task = input("Enter a new task: ")
tasks.append(task)
print(f"Task '{task}' added!")
Step 3: Viewing Tasks
def view_tasks():
if not tasks:
print("No tasks found.")
else:
print("\nYour Tasks:")
for i, task in enumerate(tasks, 1):
print(f"{i}. {task}")
Step 4: Deleting a Task
def delete_task():
view_tasks()
try:
task_num = int(input("Enter task number to delete: "))
removed = tasks.pop(task_num - 1)
print(f"Task '{removed}' deleted.")
except (ValueError, IndexError):
print("Invalid task number!")
Step 5: Saving Tasks to File
def save_tasks():
with open("tasks.txt", "w") as f:
for task in tasks:
f.write(task + "\n")
print("Tasks saved to file. Goodbye!")
Step 6: Main Loop
while True:
show_menu()
choice = input("Choose an option: ")
if choice == "1":
add_task()
elif choice == "2":
view_tasks()
elif choice == "3":
delete_task()
elif choice == "4":
save_tasks()
break
else:
print("Invalid choice, try again!")
Sample Run
=== To-Do List App ===
1. Add Task
2. View Tasks
3. Delete Task
4. Save & Exit
Choose an option: 1
Enter a new task: Study Python
Task 'Study Python' added!
Conclusion
Aapne ek simple To-Do List App banaya jo user input, loops, lists, file handling aur functions use karta hai. Ye project aapko beginners track ke saare concepts apply karne me madad karega.