Temp
By: Salar Khosravi • 2026-07-30 18:19
HTML Code
# tasks = {
# '1': {
# 'title': 'call mom',
# 'status': 'pending'
# },
# '2': {'title': 'buy food', 'status': 'done'},
# '3': {'title': 'read book', 'status': 'deleted'},
# '4': {'title': 'smt', 'status': 'pending'},
# }
import json
with open('data.json', 'r') as f:
tasks = json.load(f)
def echo_menu():
print('\n'*3)
print('='*50)
print('1- Add task')
print('2- Delete task')
print('3- Edit task')
print('4- Done task')
print('5- List Tasks')
print('6- Exit')
def add_task():
id = str(len(tasks) + 1)
title = input('what title: ')
tasks.update({
id: {
'title': title,
'status': 'pending'
},
})
print('i add the task successfully')
def edit_task(type):
id = input('which id: ')
if id not in tasks.keys():
print('id is not valid')
else:
tasks[id]['status'] = type
print(f'task {type} successfully')
def edit_title():
id = input('which id: ')
if id not in tasks.keys():
print('id is not valid')
else:
new_title = input('insert new title: ')
tasks[id]['title'] = new_title
print('title has changed successfully')
def save_data(data):
with open('data.json', 'w') as f:
json.dump(data, f)
print('data save successfully')
def show_task_list():
for id in tasks:
print(id, tasks[id]['title'])
def main():
while True:
save_data(tasks)
echo_menu()
command = input('select from menu: ')
match command:
case '1':
add_task()
case '2':
edit_task('deleted')
case '3':
edit_title()
case '4':
edit_task('done')
case '5':
show_task_list()
case '6':
break
case _:
print('command is not valid')
main()
Download