Skip to content

Commit 75061c3

Browse files
Adding progress on lab 2. Currently working on version 2.
1 parent 96f7ac4 commit 75061c3

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

code/zach/contacts.csv

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
Name,Phone,Email
22
Zachary Christman,703-555-6666,[email protected]
3-
Sara Beth,703-666-7777,[email protected]
3+
Sara Beth,703-666-7777,[email protected] Young, 1234567890, [email protected]
4+
Justin Young, 1234567890, [email protected]

code/zach/lab11-contact-list.py

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,52 @@
11
def version1():
22
with open('contacts.csv', 'r') as file:
33
lines = file.read().split('\n')
4-
#print(lines)
5-
4+
contacts = []
65
index = 1
76
headers = lines[0].split(",")
87

98
while index < len(lines):
109
contact = lines[index].split(",")
11-
print(dict(zip(headers, contact)))
10+
contacts.append(dict(zip(headers, contact)))
1211
index += 1
12+
13+
return contacts
1314

1415
def version2():
1516

16-
return 0
17+
query_type = input("What would you like to do?\nCreate\nRetrieve\nUpdate\nDelete\n> ")
1718

19+
if query_type == 'Create':
20+
with open('contacts.csv', 'a') as file:
21+
name = input("What is the contact's name? ")
22+
phone = input("What is the contact's phone? ")
23+
email = input("What is the contact's email? ")
24+
file.write(f'\n{name}, {phone}, {email}')
25+
26+
elif query_type == 'Retrieve':
27+
contacts = version1()
28+
name = input("What is the contact's name? ")
29+
index = 0
30+
31+
while index < len(contacts):
32+
if name == contacts[index]['Name']:
33+
return print(contacts[index])
34+
index += 1
35+
else:
36+
return print("User not found.")
37+
38+
#elif query_type == 'Update':
39+
40+
#elif query_type == 'Delete':
41+
42+
#else:
43+
1844
def version3():
1945

2046
return 0
2147

2248
def main():
23-
version1()
49+
#version1()
50+
version2()
2451

2552
main()

0 commit comments

Comments
 (0)