r/PythonLearning • • Apr 27 '26

Showcase the task thing’s easy 😅

Post image

i wrote it but the save/load part is ai, rest is all me. what y'all think?

63 Upvotes

21 comments sorted by

View all comments

2

u/joetato_of_syracuse Apr 28 '26

m o n o s p a c e

2

u/l__lj Apr 28 '26

import json

def show_menu(): print("""

  1. show menu

  2. show all tasks

  3. add task

  4. delete tasks

  5. toggle tasks status

  6. edit tasks

  7. save tasks

  8. load tasks

  9. exit """) def show_all_tasks(tasks): if not tasks: print("not tasks.") else: for i,task in enumerate(tasks , start=1): status = "✓" if task["completed"] else "×" print(f"{i}.{task['task']} {status}") print(("-"*30)) def add_tasks(tasks): task_text = input("Enter new task : \n") new_task = {'task': task_text, 'completed':False} tasks.append(new_task) print("Task added successfully")

def delete_tasks(tasks): try: index = int(input("task number u wanna delete:\n")) if 0 < index <= len(tasks): tasks.pop(index - 1 ) print("Task deleted successfully!")

    else:
        print("Invalid task number.")
except ValueError:
    print("Please enter a valid number")

def toggle_status(tasks): try: num = int(input("task number u wanna edit:\n")) index = num - 1 if 0<= index < len(tasks): tasks[index]['completed'] = not tasks[index]['completed'] status = "✓" if tasks[index]["completed"] else "×" print(f"Task #{num} status changed to: {status}") except ValueError: print("Please enter a valid number")

def edit_tasks(tasks): try: num = int(input("task number u wanna edit:\n")) index = num - 1 if 0 <= index < len(tasks): new_task = input("enter new task:\n") tasks[index]['task'] = new_task print("Task updated successfully!") else: print("Invalid task number") except ValueError: print("Please enter a valid number")

def save_tasks(tasks): try: with open("tasks.json" , "w" , encoding = "utf-8") as file: json.dump(tasks, file, ensure_ascii= False, indent=4) print("✅ Tasks saved successfully!") except Exception as e: print(f"❌ Error saving tasks: {e}")

def load_tasks(): try: with open("tasks.json", "r", encoding = "utf-8") as file: tasks = json.load(file) print("✅ Tasks loaded successfully!") return tasks except FileNotFoundError: print("⚠️ No saved tasks found. Starting with empty list.") return [] except Exception as e: print(f"❌ Error loading tasks: {e}") return [] tasks = load_tasks()

while True: try: choice = int(input("Enter number: \n")) except ValueError: print("not a number!") print("Please pick a number from the list!") continue if choice == 0: print("Goodbye") break elif choice == 1: show_menu() elif choice == 2: show_all_tasks(tasks) elif choice == 3: add_tasks(tasks) elif choice == 4: delete_tasks(tasks) elif choice == 5: toggle_status(tasks) elif choice == 6: edit_tasks(tasks) elif choice == 7: save_tasks(tasks) elif choice == 8 : load_tasks() else: print("Please pick a number from the list!")

0

u/l__lj Apr 28 '26

sorry, what do u mean? 🫠

3

u/joetato_of_syracuse Apr 28 '26

Monospace fonts, the default typeface for most code editors, where all characters and symbols have the same width. It is for readability of the code and has nothing to do with the program’s functionality. So perhaps don’t mind me, I am just some old man talking to myself.

2

u/joetato_of_syracuse Apr 28 '26

Which also made me wonder, which editor are you using, and did you choose the font yourself?

1

u/l__lj Apr 28 '26

the pic doesn’t support fonts, i’m using acode on my phone. still a noob at this stuff, idk how to put text on the pic or anything

1

u/howreudoin Apr 28 '26

It‘s okay not to know something. It‘s not okay to not just google the answer. In this case, the answer to your question would‘ve been just a few seconds away.

This goes for all things programming-related.