Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # menu
- # choice
- # decision
- import os #os.system
- todos = [] #global variable , external variable
- def printMenu():
- os.system('cls')
- print('0-Exit')
- print('1-Print Todo List')
- print('2-Add new Todo')
- print('3-Delete Finished')
- answer = input('Choose (0,1,2,3): ')
- answer = int(answer)
- return answer
- def printTodo():
- print('Todo List')
- print('----------')
- count = 1
- if len(todos)==0:
- print('No more todo')
- return
- for todo in todos:
- print(f'{count}-{todo}')
- count+=1
- def deleteFinishedTodo():
- printTodo()
- todel = input('enter item no. to delete: ')
- todel = int(todel) - 1 #index start from zero
- if todel >= len(todos):
- print('index out of Range error')
- os.system('pause')
- return
- todos.pop(todel) #del data at position todel
- print('Selected Item is deleted')
- if __name__ == '__main__':
- while True:
- ans = printMenu()
- if ans == 0:
- os.system('cls')
- exit(0)
- elif ans == 1:
- printTodo()
- elif ans == 2:
- newtodo = input('Enter new todo: ')
- todos.append(newtodo)
- elif ans==3:
- deleteFinishedTodo()
- os.system('pause')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement