-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsql_beans_tutorial.py
55 lines (42 loc) · 1.43 KB
/
sql_beans_tutorial.py
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
import database
MENU_PROMPT = """
Choose option:
1. Add a new bean
2. See all beans
3. Find a bean by name
4. See best preparation
5. Exit
"""
def menu():
connection = database.connect()
database.create_tables(connection)
while (user_input := input(MENU_PROMPT)) != "5":
if user_input == "1":
prompt_add_new_bean(connection)
elif user_input == "2":
prompt_see_all_beans(connection)
elif user_input == "3":
prompt_find_bean(connection)
elif user_input == "4":
prompt_find_best_method(connection)
else:
print("Invalid input")
def prompt_add_new_bean(connection):
name = input("Enter bean name: ")
method = input("Enter preparation method: ")
rating = int(input("Enter rating: "))
database.add_bean(connection, name, method, rating)
def prompt_see_all_beans(connection):
beans = database.get_all_beans(connection)
for bean in beans:
print(f"{bean[1]} {bean[2]} - {bean[3]}/ 100 ")
def prompt_find_bean(connection):
name = input("Enter bean name to find: ")
beans = database.get_beans_by_name(connection, name)
for bean in beans:
print(f"{bean[1]} {bean[2]} - {bean[3]}/ 100")
def prompt_find_best_method(connection):
name = input("Enter bean name to find: ")
best_method = database.get_best_preparation_for_bean(connection, name)
print(f"The best bean preparation for {name} is: {best_method[2]}.")
menu()