Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os #os.system() #cls
- #global variable
- todo = []
- def addTasks():
- global todo
- while True:
- task = input('task to add: ')
- if task == 'exit':
- print('bye')
- break
- todo.append(task)
- def printTodo():
- num = 0
- for task in todo:
- print(f'{num} - {task}')
- num = num + 1
- input('...')
- def printMenu():
- print('0-Exit')
- print('1-Add Todo')
- print('2-Print Todo')
- print('3-Update Todo')
- print('4-Delete Todo')
- print('5-Save To file')
- def updateData():
- printTodo()
- ind = input('Enter index to Update: ')
- ind = int(ind)
- value = input('Enter the todo you want to update: ')
- todo[ind] = value
- print('task is updated')
- def deleteData():
- global todo
- printTodo()
- ind = input('Enter index to Delete: ')
- ind = int(ind)
- del todo[ind]
- print('task is deleted')
- def saveToFile():
- out_file = open('todo.txt','w')
- for t in todo:
- out_file.write(t+'\n')
- out_file.close()
- def readFromFile():
- global todo
- in_file = open('todo.txt','r')
- data = in_file.readlines()
- in_file.close()
- for d in data:
- d = d.rstrip() #remove '\n'
- todo.append(d)
- #Real program START HERE
- if __name__ == '__main__': #တိုက်ရိုက်ခေါ်သုံးတာ ဖြစ်ခဲ့ရင် အလုပ်လုပ်မယ်
- readFromFile()
- while True:
- os.system('cls')
- printMenu()
- ans = input('Wht is your choice: 0,1,2,3,4,5: ')
- if ans == '0':
- print('bye')
- saveToFile()
- exit(0)
- elif ans == '1':
- addTasks()
- elif ans == '2':
- printTodo()
- elif ans == '3':
- updateData()
- elif ans == '4':
- deleteData()
- elif ans == '5':
- saveToFile()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement