Skip to content

Commit 6781c0e

Browse files
committed
worked later on it
1 parent e0512da commit 6781c0e

File tree

2 files changed

+81
-19
lines changed

2 files changed

+81
-19
lines changed

code/justin/contacts.csv

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ Justin,5558675309,MS,mick jagger
33
Jane, 1115558798, CA, turtle
44
Mick, 8887775498, PA, woodpecker
55
Sam, 9876543215, AR, hogger
6-
x
7-
x
8-
x
9-
x
6+
Happy,Gilmore,VA,croc
7+
Chad,highschool,HS,Bunny
8+
dingus,berry,mi,berry

code/justin/files.py

Lines changed: 78 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,79 @@
77
dic={}
88
p=1
99
new_entry = []
10-
n = input('enter a name: ')
11-
new_entry.append(n)
12-
ph = input('enter a phone number: ')
13-
new_entry.append(ph)
14-
st = input(f'enter {n}\'s state: ')
15-
new_entry.append(st)
16-
sa = input(f'enter {n}\'s spirit animal: ')
17-
new_entry.append(sa)
18-
with open('contacts.csv', 'a') as file:
19-
for x in new_entry:
20-
file.write(f'\nx')
10+
11+
12+
while True:
13+
print('''\nWelcome to our contact database, please select from the following options:
14+
To create new user enter "create":
15+
To retrive an existing record enter "search":
16+
To update an existing record enter "update":
17+
To delete a record, enter "delete":
18+
When finished, enter"done":''')
19+
a = input("Enter: ")
20+
if a.lower() == 'done':
21+
False
22+
break
23+
24+
elif a.lower() == 'create':
25+
print('\nYou selected to enter a new user follow the commands')
26+
n = input('enter a name: ')
27+
new_entry.append(n)
28+
ph = input('enter a phone number: ')
29+
new_entry.append(ph)
30+
st = input(f'enter {n}\'s state: ')
31+
new_entry.append(st)
32+
sa = input(f'enter {n}\'s spirit animal: ')
33+
new_entry.append(sa)
34+
j = ','.join(new_entry)
35+
with open('contacts.csv', 'a') as file:
36+
file.write(f'\n{j}')
37+
elif a.lower() == 'search':
38+
print('What user are you looking for?')
39+
n = input('enter name: ')
40+
with open('contacts.csv', 'r') as file:
41+
lines = file.read().split('\n')
42+
for l in lines:
43+
if n.lower() in l.lower():
44+
print(f'User {n} found: \n---------------------------------------------\n{l}')
45+
print('---------------------------------------------')
46+
elif a.lower() == 'update':
47+
n = input('what name are we looking for: ')
48+
with open('contacts.csv', 'r') as file:
49+
lines = file.read().split('\n')
50+
for l in lines:
51+
spl = l.split(',')
52+
print(spl)
53+
if n.lower() in l.lower():
54+
spl = l.split(',')
55+
spl_a = spl.copy()
56+
print(f'{l} \nis the info on file, what needs to change:\nname,phone,state,spirit animal? ')
57+
a = input('Enter what to change: ')
58+
if a.lower() == 'name':
59+
60+
61+
# if a.lower() == 'name':
62+
63+
64+
65+
66+
67+
68+
69+
70+
71+
# n = input('enter a name: ')
72+
# new_entry.append(n)
73+
# ph = input('enter a phone number: ')
74+
# new_entry.append(ph)
75+
# st = input(f'enter {n}\'s state: ')
76+
# new_entry.append(st)
77+
# sa = input(f'enter {n}\'s spirit animal: ')
78+
# new_entry.append(sa)
79+
# j = ','.join(new_entry)
80+
# with open('contacts.csv', 'a') as file:
81+
# file.write(f'\n{j}')
82+
2183

2284

2385
# with open('contacts.csv', 'a') as file:
@@ -30,13 +92,14 @@
3092
contacts.append(l.split(','))
3193
for c in contacts[0]:
3294
keys.append(c)
33-
contacts.append(new_entry)
95+
# contacts.append(new_entry)
3496
while p < len(contacts):
3597
a = dic.copy()
98+
b = contacts[p].copy()
3699
for k in keys: # k is contacts[0](headers.csv) iterated over
37-
for c in contacts[p]: # c is each contacts information iterated over
38-
x = contacts[p].index(c)
39-
contacts[p].pop(x)
100+
for c in b:
101+
x=b.index(c)
102+
b.pop(x)
40103
a[k] = c
41104
break
42105
p+=1

0 commit comments

Comments
 (0)