Advertisement
DrAungWinHtut

todo.py

Jan 13th, 2025 (edited)
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.31 KB | None | 0 0
  1. # menu
  2. # choice
  3. # decision
  4. import os #os.system
  5. todos = []  #global variable , external variable
  6.  
  7. def printMenu():
  8.     os.system('cls')
  9.     print('0-Exit')
  10.     print('1-Print Todo List')
  11.     print('2-Add new Todo')
  12.     print('3-Delete Finished')
  13.     answer = input('Choose (0,1,2,3):  ')
  14.     answer = int(answer)
  15.     return answer
  16.  
  17. def printTodo():
  18.     print('Todo List')
  19.     print('----------')
  20.     count = 1
  21.     if len(todos)==0:
  22.         print('No more todo')
  23.         return
  24.     for todo in todos:
  25.         print(f'{count}-{todo}')
  26.         count+=1
  27.  
  28. def deleteFinishedTodo():    
  29.     printTodo()
  30.     todel = input('enter item no. to delete: ')
  31.     todel = int(todel) - 1 #index start from zero
  32.     if todel >= len(todos):
  33.         print('index out of Range error')
  34.         os.system('pause')
  35.         return
  36.     todos.pop(todel) #del data at position todel
  37.     print('Selected Item is deleted')
  38.  
  39. if __name__ == '__main__':
  40.     while True:      
  41.         ans = printMenu()
  42.         if ans == 0:
  43.             os.system('cls')
  44.             exit(0)            
  45.         elif ans == 1:
  46.             printTodo()
  47.         elif ans == 2:
  48.             newtodo = input('Enter new todo: ')
  49.             todos.append(newtodo)
  50.         elif ans==3:
  51.             deleteFinishedTodo()
  52.  
  53.         os.system('pause')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement