Advertisement
DrAungWinHtut

todoapp.py

Feb 17th, 2024
990
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.66 KB | None | 0 0
  1. import os
  2.  
  3. todo = []
  4.  
  5. file_read = open('todo.save','r')
  6. lines = file_read.readlines()
  7. #print(lines)
  8. for line in lines:
  9.     line = line.strip()
  10.     todo.append(line)
  11. file_read.close()
  12.  
  13. #input()
  14.  
  15. while True:
  16.     os.system('cls')
  17.     print('1-Add a task')
  18.     print('2-Delete a task')
  19.     print('3-List all tasks')
  20.     print('4-Save data')
  21.     print('5-EXIT')
  22.     ans = input('Your choice?:  ')
  23.     if ans == '1':
  24.         print('Adding a task')
  25.         print('==============')
  26.         task = input('Enter a task: ')
  27.         todo.append(task)
  28.  
  29.     elif ans == '2':
  30.         print('TaskList')
  31.         print('=========')
  32.         count = 0
  33.         for t in todo:
  34.             count = count + 1
  35.             print(f'{count} - {t}')
  36.         d = input('Which one to delete: ')
  37.         d = int(d)
  38.         del todo[d-1]
  39.  
  40.         print('Updated task list')
  41.         print('==============')
  42.         count = 0
  43.         for t in todo:
  44.             count = count + 1
  45.             print(f'{count} - {t}')
  46.    
  47.     elif ans == '3':
  48.         print('TaskList')
  49.         print('=========')
  50.         count = 0
  51.         for t in todo:
  52.             count = count + 1
  53.             print(f'{count} - {t}')
  54.  
  55.     elif ans == '4':
  56.         print('Saving Data')
  57.         save_file = open('todo.save','w')
  58.         for item in todo:
  59.             save_file.write(item+'\n')
  60.         save_file.close()
  61.        
  62.    
  63.     elif ans == '5':
  64.         print('Bye')
  65.         print('Saving Data')
  66.         save_file = open('todo.save','w')
  67.         for item in todo:
  68.             save_file.write(item+'\n')
  69.         save_file.close()
  70.         exit(0)
  71.    
  72.     input('Press ENTER to continue...')
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement