-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadingWriting.py
More file actions
53 lines (45 loc) · 1.45 KB
/
readingWriting.py
File metadata and controls
53 lines (45 loc) · 1.45 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
50
51
52
53
from reading import list_entries, append_file, count_lines, \
delete_line, replace_line, make_inventory
while True:
choice = input(
"-----Menu----- \
\n'a' to add entries to list \
\n'l' to list entries \
\n'd' to delete \
\n'r' to replace \
\n'e' to exit \
\n'c' count entries \
\n'm' make an inventory from list \
\n\nEnter your choice: ")
if choice == 'a':
while True:
entry = input("Enter a string or type 'exit': ")
if entry == 'exit':
break
else:
append_file('data.txt', entry)
elif choice == 'l':
list_entries('data.txt')
elif choice == 'd':
while True:
choice = input("Enter the line you wish to delete or 'exit': ")
if choice == 'exit':
break
else:
delete_line('data.txt', choice)
elif choice == 'c':
lines = count_lines('data.txt')
print(f"\nNumber of Entries: {lines}\n")
elif choice == 'r':
while True:
entry1 = input("Enter an item to replace or 'exit': ")
if entry1 == 'exit':
break
entry2 = input("Enter the replacement or 'exit': ")
if entry2 == 'exit':
break
replace_line('data.txt', entry1, entry2)
elif choice == 'm':
make_inventory('data.txt')
else:
break