-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnine4.py
79 lines (62 loc) · 2.41 KB
/
nine4.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import pickle
import time
def main():
t=True
note=[]
filename="notebooks.dat"
try:
with open('noteboobk.dat','rb')as content:
pickle.load(content)
except IOError:
print("No default notebook was found, created one.")
with open('notebook.dat','bw')as contentwrite:
pickle.dump(note,contentwrite)
while t:
print("(1) Read the notebook")
print("(2) Add note")
print("(3) Edit a note")
print("(4) Delete a note")
print("(5) Save and quit")
userselection=input("Please select one: ")
if(userselection=='1'):
for i in note:
print(i)
elif(userselection=='2'):
noteitem=input("Write a new note: ")
noteitem=noteitem + ':::'
noteitem +=time.strftime('%x %x')
note.append(noteitem)
elif(userselection=='3'):
print("The list has",len(note),"notes.")
try:
whichitem=int(input("Which of them will be changed?: "))
print(note[whichitem])
newnote=input("Give the new note: ")
newnote =newnote+':::'
newnote +=time.strftime('%x %x')
note.pop(whichitem)
note.insert(whichitem,newnote + '\n')
except Exception:
print("Incorrect selection.")
elif(userselection=='4'):
try:
print("The list has",len(note),"notes.")
itemdelete=int(input("Which of them will be deleted?: "))
print("Deleted note",note[itemdelete])
note.pop(itemdelete)
except Exception:
print("Deleted note",note[0])
note.pop(0)
elif(userselection=='5'):
try:
writefile=open(filename,'wb')
content=pickle.dump(note,writefile)
writefile.close()
except IOError:
return False
print("Notebook shutting down, thank you.")
break
else:
t=True
if __name__=="__main__":
main()