-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnote.py
More file actions
49 lines (45 loc) · 1.41 KB
/
Copy pathnote.py
File metadata and controls
49 lines (45 loc) · 1.41 KB
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
import ast
# add: (void) -> (void)
# Purpose: Add a note to the database
def add():
with open("noteapp.txt", "r") as f:
full_list = ast.literal_eval(f.read())
print full_list
inlist = checkfn(full_list)
curnote = raw_input("Enter the note: ")
if inlist[0] == True:
full_list[inlist[2]].extend([curnote])
else:
full_list.append([inlist[1], curnote])
strlist = str(full_list)
with open("noteapp.txt", "w") as f:
f.write(strlist)
print full_list
# read: (void) -> (listof str)
# Purpose: Reads the notes of the person
def read():
with open("noteapp.txt", "r") as f:
full_list = ast.literal_eval(f.read())
inlist = checkfn(full_list)
if inlist[0] == True:
print full_list[inlist[2]][1:]
else:
callfn = raw_input("The name doesn't exist. Do you want to add it? (y,n)")
if callfn == "y":
add()
# checkfn: (listof str) -> (listof any)
# Purpose: Checks if a person is already in the database.
def checkfn(full_list):
n = 0
curname = raw_input("Enter a name: ")
lenflist = len(full_list)
checked = False
while checked == False:
if full_list[n][0] == curname:
checked = True
inlist = [True, curname, n]
elif n == lenflist - 1:
checked = True
inlist = [False, curname, n]
n = n + 1
return inlist