Skip to content

Commit

Permalink
add new project
Browse files Browse the repository at this point in the history
  • Loading branch information
otahina committed Jul 17, 2023
1 parent d2414ff commit 1917e84
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
21 changes: 21 additions & 0 deletions projects/ToDoList/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# ToDo List in Python 📒

This is a simple command-line ToDo List application written in Python.

## Features

- **Add Tasks:** You can add tasks to your ToDo list. Just type in your task when prompted.

- **Remove Tasks:** You can remove tasks from your ToDo list. You will need to provide the task number (the number displayed next to each task when displaying tasks).

- **Display Tasks:** You can display all tasks in your ToDo list in the order they were added.

- **Quit:** You can quit the application at any time.

## Usage

To run the program, you will need Python installed on your computer. Once you have Python, you can run the program from the command line by navigating to the directory containing the Python file and running the following command:

```bash
python to_do_list.py
python3 to_do_list.py
68 changes: 68 additions & 0 deletions projects/ToDoList/to_do_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
def add_task(task):
todo_list.append(task)
print("Task added!")

def remove_task(task_num):
if 0 <= task_num < len(todo_list):
del todo_list[task_num]
print("Task removed!")
else:
print("Invalid task number!")

def display_tasks():
if not todo_list: # If list is empty
print("No tasks to display.")
else:
for index, task in enumerate(todo_list, start=1):
print(f"{index}. {task}")

def get_choice():
while True:
try:
choice = int(input("Type a number: 1. Adding a task, 2. Removing a task, 3. Displaying tasks, 4. Quit: "))
if 1 <= choice <= 4:
return choice
else:
print("Invalid choice. Try again.")
except ValueError:
print("Please enter a number between 1 and 4.")

if __name__ == "__main__":

todo_list = []

print("Welcome to ToDo List!")

while True:
user_choice = get_choice()

#Adding a task
if user_choice == 1:
new_task = input("Type a new task: ")
add_task(new_task)

#Removing a task
elif user_choice == 2:
if not todo_list: # If list is empty
print("No tasks to remove.")
else:
task_num = int(input("Enter the task number to delete: ")) - 1
remove_task(task_num)

#Displaying tasks
elif user_choice == 3:
display_tasks()

#Quit
elif user_choice == 4:
print("Goodbye!")
break


#####################################

# CODE CONTRIBUTED BY: Ota Hina

#####################################


0 comments on commit 1917e84

Please sign in to comment.