-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
58 lines (49 loc) · 1.72 KB
/
main.py
File metadata and controls
58 lines (49 loc) · 1.72 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
54
55
56
57
58
def main():
try:
# initialize books list
booksList = []
infile = open("Booklist.txt", "r")
line = infile.readline()
while line:
booksList.append(line.rstrip("\n").split(","))
line = infile.readline()
infile.close()
except FileNotFoundError:
print("the <Booklist.txt> file is not found ")
print("Starting a new list of books!")
booksList = []
choice = 0
while choice != 4:
print("*** Bookstore Manager ***")
print("1) Want to add a book")
print("2) Want to lookup a book")
print("3) Want to Display all books")
print("4) I Quit")
choice = int(input())
if choice == 1:
print("Adding a book...")
nBook = input("Enter the name of the book >>>")
nAuthor = input("Enter the name of the author >>>")
rBefore = input("Is it a good read ? >>>")
nPages = input("How many pages are there >>>")
booksList.append([nBook, nAuthor, rBefore, nPages])
elif choice == 2:
print("Looking up for a book...")
keyword = input("Enter Search Term: ")
for book in booksList:
if keyword in book:
print(book)
elif choice == 3:
print("Displaying all books...")
for i in range(len(booksList)):
print(booksList[i])
elif choice == 4:
print("Quitting Program")
print("Program Terminated!")
# Saving to external TXT file
outfile = open("theBooksList.txt", "w")
for book in booksList:
outfile.write(",".join(book) + "\n")
outfile.close()
if __name__ == "__main__":
main()