from sqlite3 import * conn = connect("/home/stephen/teaching/350/bj.db") cursor = conn.execute("SELECT * FROM RECIPE") # "embedded SQL" rows = cursor.fetchall() # Prompt the user for their favorite flavor (or done) and return it. def fave_flavor(): flavor = input("What's your favorite base flavor? (or 'done') ") return flavor print("Hello user!") the_input = fave_flavor() while the_input != "done": print(f"Which {the_input}-based recipe would you like to order?") # BAD AND UNSAFE!! ZOMGGGGGG!! #cursor = conn.execute( # f"SELECT name FROM recipe WHERE flavorName={the_input}") # Good and happy and copacetic cursor = conn.execute( "SELECT name FROM recipe WHERE flavorName=?", (the_input,) ) recipe_names = cursor.fetchall() x = 1 for recipe_name in recipe_names: print(f"{x}. {recipe_name[0]}") x += 1 number = int(input("Your choice? ")) recipe_to_order = recipe_names[number-1][0] cartons_ordered = int(input( f"How many cartons of {recipe_to_order} do you want? ")) conn.execute( "UPDATE recipe SET cartonsOrdered=cartonsOrdered+? where " "name=?", (cartons_ordered, recipe_to_order) ) conn.commit() the_input = fave_flavor() print("Goodbye!")