-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapps.py
More file actions
55 lines (37 loc) · 1.19 KB
/
apps.py
File metadata and controls
55 lines (37 loc) · 1.19 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
from utils import database
USER_CHOICE = """
Enter:
'a' to add a new book
'l' to list all books
'r' to mark a book as read
'd' to delete a book
'q' to quit
Your choice: """
def menu():
database.create_book_table()
user_input = input(USER_CHOICE)
while user_input != 'q':
if user_input == 'a':
prompt_add_book()
elif user_input == 'l':
list_books()
elif user_input == 'r':
prompt_read_book()
elif user_input == 'd':
prompt_delete_book()
user_input = input(USER_CHOICE)
def prompt_add_book():
name = input('Enter the new book name: ')
author = input('Enter the new book author: ')
database.insert_book(name, author)
def list_books():
for book in database.get_all_books():
read = 'YES' if book[3] else 'NO' # book[3] will be a falsy value (0) if not read
print(f'{book[1]} by {book[2]} — Read: {read}')
def prompt_read_book():
name = input('Enter the name of the book you just finished reading: ')
database.mark_book_as_read(name)
def prompt_delete_book():
name = input('Enter the name of the book you wish to delete: ')
database.delete_book(name)
menu()