|
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.
|
|
|
|
|
I recommend to create database tables after you connect to the database.
put this code at after creating conn variable to avoid tables does not exists issue.
conn = sqlite3.connect('Chef__Order.db')
conn.execute("""CREATE TABLE IF NOT EXISTS "Chef" ( "ChefID" TEXT NOT NULL, "Chefs" TEXT NOT NULL, "Meals cooked No." INTEGER, PRIMARY KEY("ChefID","Chefs") )""")
conn.execute("""CREATE TABLE IF NOT EXISTS "Food" ("FoodID" INTEGER, "Food names" TEXT, "Ratings" INTEGER, "Price" INTEGER, PRIMARY KEY("Price", "Food names", "FoodID"))""")
conn.execute("""CREATE TABLE IF NOT EXISTS "Members" ("ID" TEXT NOT NULL, "Names" TEXT, "Feedback" INTEGER, PRIMARY KEY("ID","Names"))""")
conn.execute("""CREATE TABLE IF NOT EXISTS "Progression" ("OrderNo" INTEGER, "ID" TEXT, "Food" TEXT, "Quantity" INTEGER, "Price" REAL, "Progress" TEXT, FOREIGN KEY("ID") REFERENCES "Members"("ID"))""")
This code will create table if it already does not exists and if it already exists it will not through any error and the program will run just fine.
|
|
|
|
|
Hi,
I am trying to understand a code in python:
what something similar to mystruct((0x03).to_byte(),'little') means?. trying to convert it to c.
|
|
|
|
|
You need to provide more details of the actual code you are referring to. Where is the definition of mystruct ?
|
|
|
|
|
please send the codes, i can learn from that
|
|
|
|
|
That's not how this works. The only code you're ever going to get is the code YOU write.
Nobody is going to do your work for you.
|
|
|
|
|
Dave Kreskowiak wrote: That's not how this works.
Yeah - he forgot to type in ALL CAPS, and missed the magic "ITS URGENTZ!!!!1!!" from the end of the "SEND TEH CODEZ NAO" demand.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
A walking, talking cliche.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
I wondered if I should spent the 5 minutes to direct the OP in the right direction, and yeah, he deserves it fully
Quote: What is Coding? “Writing code,” “coding,” and “programming” are basically interchangeable terms. Broadly speaking, knowing how to write code is the process of creating instructions that tell a computer what to do, and how to do it. Codes are written in various languages, such as JavaScript, C#, Python, and much more.
|
|
|
|
|
What is the difference between "C:\\my folder" and r"C:\my folder" in Python?
Can the "C:\\my folder" be written as r"C:\my folder"?
Thanks.
modified 12-Oct-23 13:00pm.
|
|
|
|
|
Unless an ‘r’ or ‘R’ prefix is present, escape sequences in strings are interpreted according to rules similar to those used by Standard C.
...
When an ‘r’ or ‘R’ prefix is present, a character following a backslash is included in the string without change, and all backslashes are left in the string.
Thus "C:\\folder" and r"C:\folder" represent the same string.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
Certainly! In Python, the difference between `"C:\\my folder"` and `r"C:\my folder"` lies in how they handle backslashes within strings:
1. **`"C:\\my folder"`:**
- This is a regular Python string where the backslash `\` is an escape character. When you use `\\`, it represents a single backslash in the resulting string.
- For example, `"C:\\my folder"` would be interpreted as `"C:\my folder"` when used in code.
2. **`r"C:\my folder"`:**
- The `r` prefix before the string denotes a raw string in Python. In a raw string, backslashes are treated as literal characters and are not interpreted as escape characters.
- So, `r"C:\my folder"` represents the string exactly as it is, including the backslash, and results in `"C:\my folder"`.
Yes, you can achieve the same result by using a raw string. Both `"C:\\my folder"` and `r"C:\my folder"` represent the same file path, but using a raw string often makes code more readable and avoids potential confusion with escape sequences.
|
|
|
|
|
Posting answers generated by an AI chatbot without clearly marking them as such will result in your account being closed.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I want to know which software you use for detecting AI generated content?
|
|
|
|
|
I use the most advanced pattern-recognition system ever developed: the human brain.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
# Gives the name of the game
print ("\t FLAMES")
print ("\n")
# Take input from user
# And Saved them in lowercase
name1 = input("Name of the first person : ").lower()
name2 = input("Name of the second person : ").lower()
print ("\n")
# If there any space in between names
# In this stage removing all the spaces
rename1 = name1.replace(" ", "")
rename2 = name2.replace(" ", "")
# Added those name
name = rename1 + rename2
# In here removing same characters
for x in name:
if name.count(x) != 1:
name = name.replace(x,"")
# Check total number of remaining characters
number = len(name)
# List of FLAMES acronym
result = ["Friends","Love","Affection","Marriage","Enemy","Siblings"]
while number > 1 :
split_result = (number % len(result) -1)
if split_result >= 0 :
right = result[split_result + 1:]
left = result[: split_result]
result = right + left
else:
result = result[: len(result) - 1]
print("Relationship status :", result[0])
#"split_result = (number % len(result) -1) " SHOWS THAT THERE IS ZERODIVITION ERROR HOW TO CORRECT THAT ?
|
|
|
|
|
The issue is with the loop at:
while number > 1 :
split_result = (number % len(result) -1)
if split_result >= 0 :
right = result[split_result + 1:]
left = result[: split_result]
result = right + left
else:
result = result[: len(result) - 1]
You never decrement the value of number so the loop will continue forever, or until some exception occurs. But it is not clear what the code inside the loop is supposed to do, so that also may need some reworking.
[edit]
Having looked again at this code I am not sure that the while statement above is correct. Try replacing it with if instead, thus:
if number > 1:
[/edit]
modified 8-Oct-23 4:23am.
|
|
|
|
|
Thank you so much for your help sir .... I understand what mistake was i done. In while loop I typed
" while number > 0: " that was the mistake i done. I changed that comment into " while len(reult) > 1:".
Now its okey sir. Thank you sir ,Thank you so much for your valuble time
|
|
|
|
|
I am trying to get the Coral M.2 card working with CPAI. This is on a new clean Windows build, where I followed the guidance referenced from this page Coral TPU really does its work for CP.AI object recognition! - Blue Iris
All seems OK with CPAI itself but I can't get the Coral module loaded - it throws these errors:
21:31:27:Error trying to start ObjectDetection (Coral) (objectdetection_coral_adapter.py)
21:31:27:An error occurred trying to start process 'C:\Program Files\CodeProject\AI\modules\ObjectDetectionCoral\bin\windows\python37\venv\scripts\Python' with working directory 'C:\Program Files\CodeProject\AI\modules\ObjectDetectionCoral'. The system cannot find the file specified.
21:31:27: at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
at CodeProject.AI.Server.Modules.ModuleProcessServices.StartProcess(ModuleConfig module)
21:31:27:Please check the CodeProject.AI installation completed successfully
The folder exists, but is empty. Have I missed a step in installation? What is the best way to fix this, please? Any advice would be much appreciated. Thanks.
|
|
|
|
|
|
OK, I will do. Apologies if this is the wrong place.
|
|
|
|
|
It's not so much that this is the wrong place. But there is a dedicated forum for the CodeProject AI system, and you are much more likely to get expert help there.
|
|
|
|
|