Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pickle
- class Item(object):
- def __init__(self,D,P,DD):
- self.description = D
- self.priority = p
- self.dueDate = DD
- def Update(self, num, info):
- if num == 1 :
- self.description = info
- elif num == 2:
- self.priority = info
- elif num == 3:
- self.dueDate = info
- else:
- print("no valid")
- def printList():
- count = 1;
- for i in toDoList:
- print(str(count) + ". " + i.description + " priority is " + i.priority + " due on :" + i.dueDate)
- count += 1;
- filename = "todolist2.pickle"
- #==== Open To Do List File and Load into memory ===
- try:
- f = open(filename, 'rb')
- toDoList = pickle.load(f)
- f.close()
- except:
- print("Creating new file..")
- toDoList = []
- #=== Run Program ===
- runFlag = True
- while runFlag:
- #=== Main program selection ===
- response = input("""What do you want to do?
- C: Create a new to do item
- S: Display your to do list
- U: UPdate Item in List
- D: Delete an item from your to do list
- E: Exit program\n>>""")
- #=== Create new to do ===
- if response == "C":
- d = input("What u wan do? \n");
- p = input("What is the priority? \n");
- dd = input("What is the due date? \n");
- newItem = Item(d,p,dd)
- toDoList.append(newItem)
- printList()
- #=== Show to do list ===
- elif response == "S":
- printList()
- #=== Delete To Do Item ===
- elif response == "D":
- i = int(input("What num to delete? \n" ))
- toDoList.pop(i-1)
- printList()
- elif response == "U":
- i = int(input("What item to update? \n"))
- j = int(input("What do you want to update? \n 1. Description \n 2. Priority \n 3. DueDate \n" ))
- info = input("Update to wat? \n" )
- toU = toDoList[i-1]
- toU.Update(j,info)
- toDoList[i-1] = toU
- printList()
- #=== Exit Program ===
- elif response == "E":
- f = open(filename, 'wb')
- pickle.dump(toDoList, f)
- f.close()
- runFlag = False
- else:
- print("Invalid input. Please try again\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement