Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. import pickle
  2. class Item(object):
  3. def __init__(self,D,P,DD):
  4. self.description = D
  5. self.priority = p
  6. self.dueDate = DD
  7.  
  8. def Update(self, num, info):
  9. if num == 1 :
  10. self.description = info
  11. elif num == 2:
  12. self.priority = info
  13. elif num == 3:
  14. self.dueDate = info
  15. else:
  16. print("no valid")
  17.  
  18.  
  19. def printList():
  20. count = 1;
  21. for i in toDoList:
  22. print(str(count) + ". " + i.description + " priority is " + i.priority + " due on :" + i.dueDate)
  23. count += 1;
  24.  
  25.  
  26. filename = "todolist2.pickle"
  27.  
  28. #==== Open To Do List File and Load into memory ===
  29. try:
  30. f = open(filename, 'rb')
  31. toDoList = pickle.load(f)
  32. f.close()
  33. except:
  34. print("Creating new file..")
  35. toDoList = []
  36.  
  37. #=== Run Program ===
  38.  
  39. runFlag = True
  40. while runFlag:
  41. #=== Main program selection ===
  42. response = input("""What do you want to do?
  43. C: Create a new to do item
  44. S: Display your to do list
  45. U: UPdate Item in List
  46. D: Delete an item from your to do list
  47. E: Exit program\n>>""")
  48.  
  49. #=== Create new to do ===
  50. if response == "C":
  51.  
  52. d = input("What u wan do? \n");
  53. p = input("What is the priority? \n");
  54. dd = input("What is the due date? \n");
  55. newItem = Item(d,p,dd)
  56. toDoList.append(newItem)
  57. printList()
  58.  
  59.  
  60. #=== Show to do list ===
  61. elif response == "S":
  62. printList()
  63.  
  64. #=== Delete To Do Item ===
  65. elif response == "D":
  66. i = int(input("What num to delete? \n" ))
  67. toDoList.pop(i-1)
  68. printList()
  69.  
  70. elif response == "U":
  71. i = int(input("What item to update? \n"))
  72. j = int(input("What do you want to update? \n 1. Description \n 2. Priority \n 3. DueDate \n" ))
  73. info = input("Update to wat? \n" )
  74. toU = toDoList[i-1]
  75. toU.Update(j,info)
  76. toDoList[i-1] = toU
  77. printList()
  78.  
  79. #=== Exit Program ===
  80. elif response == "E":
  81. f = open(filename, 'wb')
  82. pickle.dump(toDoList, f)
  83. f.close()
  84. runFlag = False
  85.  
  86. else:
  87. print("Invalid input. Please try again\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement