|
I would like to request assistance with my code, where when inserting a table into the database from Python, the system replies with an error that says that the table is not nonexistent. However, the table is there.
Cafeteria.py
import sqlite3
from Chef_staff import *
conn = sqlite3.connect('Chef__Order.db')
curs = conn.cursor()
MembersID = {'Aria': 'ID001', 'Barston': 'ID002', 'CJ': 'ID003', 'Damarsh': 'ID004', 'Elaine': 'ID005'}
MembersFeedback = {'Aria': 0, 'Barston': 0, 'CJ': 0, 'Damarsh': 0, 'Elaine': 0}
MembersOrder = {'Aria': 0, 'Barston': 0, 'CJ': 0, 'Damarsh': 0, 'Elaine': 0}
Food = {'Burger': 5.00, 'Pancakes': 2.00, 'Sandwiches': 2.50, 'Steak': 10.00, 'Fries': 1.50, 'Tea': 0.50, 'Coffee': 0.75}
FoodRating = {'Burger': 0, 'Pancakes': 0, 'Sandwiches': 0, 'Steak': 0, 'Fries': 0, 'Tea': 0, 'Coffee': 0}
order_no = 0
burger_rate = 0
pancake_rate = 0
sandwich_rate = 0
steak_rate = 0
fries_rate = 0
tea_rate = 0
coffee_rate = 0
accumalated_b = 0
accumalated_p = 0
accumalated_sw = 0
accumalated_st = 0
accumalated_f = 0
accumalated_t = 0
accumalated_c = 0
while True:
order_option = False
login = input('Please enter your member username: ')
for i in MembersID:
if login == i:
while order_option == False:
price = 0
order_no =+ 1
order = int(input('Please select which food you would like to order\n1. Burger\n2. Pancakes\n3. Sandwiches\n4. Steak\n5. Fries\n6. Tea\n7. Coffee\n'))
if order == 1:
amount_order = int(input('How many burgers would you like to order?\n'))
MembersOrder[i] += amount_order
print(f'You have ordered {amount_order} Burger, {login}')
price = Food['Burger'] * amount_order
curs.execute(f'INSERT INTO Progression (OrderNo, ID, Food, Quantity, Price) VALUES ({order_no},{MembersID[i]},"Burger",{amount_order},{price})')
elif order == 2:
amount_order = int(input('How many pancake would you like to order?\n'))
MembersOrder[i] += amount_order
print(f'You have ordered {amount_order} Pancakes, {login}')
price = Food['Pancakes'] * amount_order
curs.execute(f'INSERT INTO Progression (OrderNo, ID, Food, Quantity, Price) VALUES ({order_no},{MembersID[i]},"Pancakes",{amount_order},{price})')
elif order == 3:
amount_order = int(input('How many sandwich would you like to order?\n'))
MembersOrder[i] += amount_order
print(f'You have ordered {amount_order} Sandwiches, {login}')
price = Food['Sandwiches'] * amount_order
curs.execute(f'INSERT INTO Progression.tbl (OrderNo, ID, Food, Quantity, Price) VALUES ({order_no},{MembersID[i]},"Sandwiches",{amount_order},{price})')
elif order == 4:
amount_order = int(input('How many Steak would you like to order?\n'))
MembersOrder[i] += amount_order
print(f'You have ordered {amount_order} Steak, {login}')
price = Food['Steak'] * amount_order
curs.execute(f'INSERT INTO Progression (OrderNo, ID, Food, Quantity, Price) VALUES ({order_no},{MembersID[i]},"Steak",{amount_order},{price})')
elif order == 5:
amount_order = int(input('How many packet of fries would you like to order?\n'))
MembersOrder[i] += amount_order
print(f'You have ordered {amount_order} packet of fries, {login}')
price = Food['Fries'] * amount_order
curs.execute(f'INSERT INTO Progression (OrderNo, ID, Food, Quantity, Price) VALUES ({order_no},{MembersID[i]},"Fries",{amount_order},{price})')
elif order == 6:
amount_order = int(input('How many tea would you like to order?\n'))
MembersOrder[i] += amount_order
print(f'You have ordered {amount_order} tea, {login}')
price = Food['Tea'] * amount_order
curs.execute(f'INSERT INTO Progression (OrderNo, ID, Food, Quantity, Price) VALUES ({order_no},{MembersID[i]},"Tea",{amount_order},{price})')
elif order == 7:
amount_order = int(input('How many coffee would you like to order?\n'))
MembersOrder[i] += amount_order
print(f'You have ordered {amount_order} coffee, {login}')
price = Food['Coffee'] * amount_order
curs.execute(f'INSERT INTO Progression (OrderNo, ID, Food, Quantity, Price) VALUES ({order_no},{MembersID[i]},"Coffee",{amount_order},{price})')
else:
print('Please enter a valid number')
order_option1 = input('Would you like to order more? Y/N\n')
if order_option1 == 'Y':
order_option = False
elif order_option1 == 'N':
order_option = True
option = input('Would you like to give a rating? (Y/N)')
if option == 'Y':
curs.execute(f'INSERT INTO Members (Feedback) VALUE (Feedback + 1)')
selection = int(input('Please select which food to rate\n1. Burger\n2. Pancakes\n3. Sandwiches\n'))
if 1 <= selection <= 7 :
rating = int(input('Please rate your experience from 1 to 5: '))
if rating > 0 and rating < 6:
if selection == 1:
burger_rate += 1
FoodRating['Burger'] = int((accumalated_b + rating) / burger_rate)
curs.execute(f'INSERT INTO Food (Ratings) Value')
elif selection == 2:
pancake_rate += 1
FoodRating['Pancakes'] = int((accumalated_p + rating) / pancake_rate)
elif selection == 3:
sandwich_rate += 1
FoodRating['Sandwiches'] = int((accumalated_sw + rating) / sandwich_rate)
elif selection == 4:
steak_rate += 1
FoodRating['Steak'] = int((accumalated_st + rating) / steak_rate)
elif selection == 5:
fries_rate += 1
FoodRating['Fries'] = int((accumalated_f + rating) / fries_rate)
elif selection == 6:
tea_rate += 1
FoodRating['Tea'] = int((accumalated_t + rating) / tea_rate)
elif selection == 7:
coffee_rate += 1
FoodRating['Coffe'] = int((accumalated_c + rating) / coffee_rate)
else:
print('valid rating is 1 to 5')
print(f'Number of orders ordered by members\n {MembersOrder}')
print(f'Current food rating\n{FoodRating}')
Database table_DB browser
CREATE TABLE "Chef" ( "ChefID" TEXT NOT NULL, "Chefs" TEXT NOT NULL, "Meals cooked No." INTEGER, PRIMARY KEY("ChefID","Chefs") )
CREATE TABLE "Food" ("FoodID" INTEGER, "Food names" TEXT, "Ratings" INTEGER, "Price" INTEGER, PRIMARY KEY("Price", "Food names", "FoodID"))
CREATE TABLE "Members" ("ID" TEXT NOT NULL, "Names" TEXT, "Feedback" INTEGER, PRIMARY KEY("ID","Names"))
CREATE TABLE "Progression" ("OrderNo" INTEGER, "ID" TEXT, "Food" TEXT, "Quantity" INTEGER, "Price" REAL, "Progress" TEXT, FOREIGN KEY("ID") REFERENCES "Members"("ID")) CREATE TABLE sqlite_sequence(name,seq)
Chef_staff.py
ChefID = {'Harlow': 'ID010', 'Benedict': 'ID011', 'Carlson': 'ID012'}
ChefOrder = {'Harlow': 0, 'Benedict': 0, 'Carlson': 0}
|
|
|
|
|
skmsjh wrote: the table is not nonexistent
Assuming that double-negative is a mistake, then the error is telling you that the table does not exist.
skmsjh wrote: However, the table is there.
You say the table is there; the error message says the table is not there. Guess which statement we're going to believe?
Start by triple-checking which database you're connecting to. Based on the code, it looks like you're connecting to a file-based database in the current working directory, which is usually the same directory as your code. You have almost certainly added the tables to a different copy of that database.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
modified 26-Feb-24 4:35am.
|
|
|
|