make a program
- User
make a program
- Assistant
Certainly! Below is a simple Python program that demonstrates a basic To-Do List application. This program will allow users to add, view, and remove tasks from their to-do list.
To-Do List Program
def display_menu(): print("\nTo-Do List Menu:") print("1. View To-Do List") print("2. Add Task") print("3. Remove Task") print("4. Exit") def view_tasks(tasks): if not tasks: print("\nNo tasks in the to-do list.") else: print("\nTo-Do List:") for idx, task in enumerate(tasks, start=1): print(f"{idx}. {task}") def add_task(tasks): task = input("Enter the task you want to add: ") tasks.append(task) print(f"Task '{task}' added to the to-do list.") def remove_task(tasks): view_tasks(tasks) if tasks: try: task_number = int(input("Enter the number of the task you want to remove: ")) if 1 <= task_number <= len(tasks): removed_task = tasks.pop(task_number - 1) print(f"Task '{removed_task}' removed from the to-do list.") else: print("Invalid task number. Please try again.") except ValueError: print("Please enter a valid number.") def main(): tasks = [] while True: display_menu() choice = input("Enter your choice: ") if choice == '1': view_tasks(tasks) elif choice == '2': add_task(tasks) elif choice == '3': remove_task(tasks) elif choice == '4': print("Exiting the To-Do List application. Goodbye!") break else: print("Invalid choice. Please enter a number between 1 and 4.") if __name__ == "__main__": main()Explanation:
-
display_menu():
- Prints the menu options for the user.
-
view_tasks(tasks):
- Displays the current tasks in the to-do list.
- If there are no tasks it will print "No tasks in the to-do list"
-
add_task(tasks):
- Prompts the user to enter a new task and adds it to the list.
-
remove_task(tasks):
- Displays the current tasks and prompts the user to enter the number of the task they want to remove.
- It will also handle if the user enters an invalid task number or a non-number input.
-
main():
- The main function that runs the program.
- It initialises an empty list
tasksto store the to-do items. - It then enters a while loop, continuously displaying the menu and processing the user's choice until the user decides to exit by choosing option 4.
To run this program, copy the code into a file named
todo_list.pyand run it using a Python interpreter:python todo_list.pyThis is a basic console-based To-Do List application. You can expand it by adding more features, such as saving the to-do list to a file, marking tasks as completed, or setting due dates for tasks.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.