Checking if an int is inside a database table.(Cash register) [closed]












-1














I am creating a cash register in one of my classes and our teacher wants us to input the Universal Postal Code(UPC). So far, I have created the table and inserted all of the products. Although there are twenty of them so i've only put three on here.



The thing I am having trouble with is on finding ways on how to check the user's input to see if it matches the UPC(the ones that says 0001,0002,0003) in the database. Or long story short, how to check if a string matches a value from a table from a database.



If you would like to see the entire coding to get a better idea, scroll down better



import sqlite3

c = conn.cursor()

c.execute('CREATE TABLE IF NOT EXISTS tblStoreItems(intUniversalProductCode
INT,strProductName TEXT,intQuantity INT,fltPrice REAL)')
conn.commit()

def funStoreItems():
c.execute("INSERT INTO
tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice)
VALUES(0001,'EGGS',421,3.5)")#1,473.5

c.execute("INSERT INTO
tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice)
VALUES(0002,'TURKEY',803,7.75)") #6,223.25

c.execute("INSERT INTO
tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice)
VALUES(0003,'HAM',921,7.25)") #6,720.75

#funStoreItems()
UPC = int(input("Please enter the UPC:"))




FULL CODE:



import sqlite3

print("Opened database successfully!")

c = conn.cursor()

c.execute('CREATE TABLE IF NOT EXISTS tblStoreItems(intUniversalProductCode INT,strProductName TEXT,intQuantity INT,fltPrice REAL)')
conn.commit()

def funStoreItems():
c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0001,'EGGS',421,3.5)")#1,473.5

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0002,'TURKEY',803,7.75)") #6,223.25

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0003,'HAM',921,7.25)") #6,720.75

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0004,'BREAD',212,4)") #848

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0005,'PANCAKE MIX',104,8)") #832

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0006,'CHEESE',742,2)") #1,484

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0007,'SAUSAGE',654,10)") #6,540

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0008,'CEREAL',1000,2)") #2,000

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0009,'MILK',1223,4.5)") #55053.5

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0010,'ORANGE JUICE',542,4)") #2,096

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0011,'SALAD',213,3)") #639

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0012,'ICE CREAM',666,5)") #3,330

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0013,'CHOCOLATE',1268,1)") #1,268

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0014,'CORN',364,3.75)") #1,365

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0015,'PASTA',196,6.75)")#1,323

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0016,'BANANA',150,4)") #600

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0017,'APPLE',407,4)") #1,628

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0018,'STEAK',545,15)") #8,175

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0019,'CARROT',312,2.5)") #802.5

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0020,'SUSHI',53,20)") #1,060

conn.commit()


def funBankAccount():
#103461.50
total_balance = float(103461.50)

wallet = print("nYour current balance is:",total_balance)

withdrawal = float(input("nHow much money would you like to draw from the bank?"))


if withdrawal > total_balance:
overload = input("nYou do not have enough to withdraw! would you just like to withdraw all of your money?").upper()

if overload == 'yes'.upper():
wallet = total_balance
print("You now have", wallet,"in your wallet.")

elif overload == 'no'.upper:
control_center()

#If the withdrawal amount is less than total balance
elif withdrawal < total_balance:
#Take away how much the user has inputted
total_balance = (total_balance - withdrawal)
#Withdraw the amount of money that the user withdrawed.
wallet = withdrawal
print("nYou now have",wallet,"in your wallet")
else:
print("Invalid! Please try again")
funBankAccount()

def funCashRegister():
print("n________________________________________________nHere are the list of things that you can buy:n==================================nItem: Eggs | UPC: 0001 nItem: Turkey | UPC: 0002 nItem: Ham | UPC: 0003 nItem: Bread | UPC: 0004 nItem: Pancake | UPC: 0005 nItem: Cheese | UPC: 0006 nItem: Sausage | UPC: 0007 nItem: Cereal | UPC: 0008 nItem: Milk | UPC: 0009 nItem: Orange Juice | UPC: 0010 nItem: Salad | UPC: 0011 nItem: Ice Cream | UPC: 0012 nItem: Chocolate | UPC: 0013 nItem: Corn | UPC: 0014 nItem: Pasta | UPC: 0015 nItem: Banana | UPC: 0016 nItem: Apple | UPC: 0017 nItem: Steak | UPC: 0018 nItem: Carrot | UPC: 0019 nItem: Sushi | UPC: 0020 n==================================")

#STEP 1)This will ask the user for the input of the UPC
#user_input_upc = int(input("nPlease enter the Universal Postal Code here for the produc tthat you are wanting to purchase today."))
UPC_or_Item = ""
UPC = int(input("Please enter the UPC:"))

#take out the numbers from the string and convert them into digits

#Otherwise if they don't type in digits then continue.



#Step 2) Retreiving Product description and price(database)
#Grab the item of the UPC then print it out telling the user how much they have to pay for it
#aaaa = float(input("How much did the customer pay you"))

#Search how to check if a string matches value in a table in a database in python

#OR check how I did that inside the password database.

#print("You have to pay", x,"before acquiring this.")


#Step 3)Give the cashier a way to signal that the transaction is complete. Afterwards, provide subtotal, tax, total cash tendered and calculate changes


#Step3.1) USE OWASSO TAX: 8.917%. Do the math

#Step3.2) Remove quantity and once it hits zero, tell the user that they can no longer purchase the item for it is out of stock.

#Step4) Print out the change and confirmation of purchase.


def control_center():

#funBankAccount()

#funStoreItems()

funCashRegister()

control_center()









share|improve this question















closed as too broad by Mureinik, stovfl, Noctis Skytower, alexi2, EdChum Nov 21 at 9:48


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.















  • Please elaborate on what part of the code is not working. In Python you can just check a string with equality (==). So if you have a UPC and user input you could do, if UPC == db_string:
    – kstullich
    Nov 20 at 19:09










  • The code is working just fine. Sorry if I didn't specifically say the question right away but it's the bolded part that says "I am having trouble on finding ways on how to check the user's input to see if it matches the UPC(the ones that says 0001,0002,0003) in the database. Or long story short, how to check if a string matches a value from a table from a database."
    – Hmongster Moua
    Nov 20 at 22:40
















-1














I am creating a cash register in one of my classes and our teacher wants us to input the Universal Postal Code(UPC). So far, I have created the table and inserted all of the products. Although there are twenty of them so i've only put three on here.



The thing I am having trouble with is on finding ways on how to check the user's input to see if it matches the UPC(the ones that says 0001,0002,0003) in the database. Or long story short, how to check if a string matches a value from a table from a database.



If you would like to see the entire coding to get a better idea, scroll down better



import sqlite3

c = conn.cursor()

c.execute('CREATE TABLE IF NOT EXISTS tblStoreItems(intUniversalProductCode
INT,strProductName TEXT,intQuantity INT,fltPrice REAL)')
conn.commit()

def funStoreItems():
c.execute("INSERT INTO
tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice)
VALUES(0001,'EGGS',421,3.5)")#1,473.5

c.execute("INSERT INTO
tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice)
VALUES(0002,'TURKEY',803,7.75)") #6,223.25

c.execute("INSERT INTO
tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice)
VALUES(0003,'HAM',921,7.25)") #6,720.75

#funStoreItems()
UPC = int(input("Please enter the UPC:"))




FULL CODE:



import sqlite3

print("Opened database successfully!")

c = conn.cursor()

c.execute('CREATE TABLE IF NOT EXISTS tblStoreItems(intUniversalProductCode INT,strProductName TEXT,intQuantity INT,fltPrice REAL)')
conn.commit()

def funStoreItems():
c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0001,'EGGS',421,3.5)")#1,473.5

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0002,'TURKEY',803,7.75)") #6,223.25

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0003,'HAM',921,7.25)") #6,720.75

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0004,'BREAD',212,4)") #848

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0005,'PANCAKE MIX',104,8)") #832

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0006,'CHEESE',742,2)") #1,484

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0007,'SAUSAGE',654,10)") #6,540

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0008,'CEREAL',1000,2)") #2,000

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0009,'MILK',1223,4.5)") #55053.5

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0010,'ORANGE JUICE',542,4)") #2,096

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0011,'SALAD',213,3)") #639

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0012,'ICE CREAM',666,5)") #3,330

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0013,'CHOCOLATE',1268,1)") #1,268

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0014,'CORN',364,3.75)") #1,365

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0015,'PASTA',196,6.75)")#1,323

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0016,'BANANA',150,4)") #600

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0017,'APPLE',407,4)") #1,628

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0018,'STEAK',545,15)") #8,175

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0019,'CARROT',312,2.5)") #802.5

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0020,'SUSHI',53,20)") #1,060

conn.commit()


def funBankAccount():
#103461.50
total_balance = float(103461.50)

wallet = print("nYour current balance is:",total_balance)

withdrawal = float(input("nHow much money would you like to draw from the bank?"))


if withdrawal > total_balance:
overload = input("nYou do not have enough to withdraw! would you just like to withdraw all of your money?").upper()

if overload == 'yes'.upper():
wallet = total_balance
print("You now have", wallet,"in your wallet.")

elif overload == 'no'.upper:
control_center()

#If the withdrawal amount is less than total balance
elif withdrawal < total_balance:
#Take away how much the user has inputted
total_balance = (total_balance - withdrawal)
#Withdraw the amount of money that the user withdrawed.
wallet = withdrawal
print("nYou now have",wallet,"in your wallet")
else:
print("Invalid! Please try again")
funBankAccount()

def funCashRegister():
print("n________________________________________________nHere are the list of things that you can buy:n==================================nItem: Eggs | UPC: 0001 nItem: Turkey | UPC: 0002 nItem: Ham | UPC: 0003 nItem: Bread | UPC: 0004 nItem: Pancake | UPC: 0005 nItem: Cheese | UPC: 0006 nItem: Sausage | UPC: 0007 nItem: Cereal | UPC: 0008 nItem: Milk | UPC: 0009 nItem: Orange Juice | UPC: 0010 nItem: Salad | UPC: 0011 nItem: Ice Cream | UPC: 0012 nItem: Chocolate | UPC: 0013 nItem: Corn | UPC: 0014 nItem: Pasta | UPC: 0015 nItem: Banana | UPC: 0016 nItem: Apple | UPC: 0017 nItem: Steak | UPC: 0018 nItem: Carrot | UPC: 0019 nItem: Sushi | UPC: 0020 n==================================")

#STEP 1)This will ask the user for the input of the UPC
#user_input_upc = int(input("nPlease enter the Universal Postal Code here for the produc tthat you are wanting to purchase today."))
UPC_or_Item = ""
UPC = int(input("Please enter the UPC:"))

#take out the numbers from the string and convert them into digits

#Otherwise if they don't type in digits then continue.



#Step 2) Retreiving Product description and price(database)
#Grab the item of the UPC then print it out telling the user how much they have to pay for it
#aaaa = float(input("How much did the customer pay you"))

#Search how to check if a string matches value in a table in a database in python

#OR check how I did that inside the password database.

#print("You have to pay", x,"before acquiring this.")


#Step 3)Give the cashier a way to signal that the transaction is complete. Afterwards, provide subtotal, tax, total cash tendered and calculate changes


#Step3.1) USE OWASSO TAX: 8.917%. Do the math

#Step3.2) Remove quantity and once it hits zero, tell the user that they can no longer purchase the item for it is out of stock.

#Step4) Print out the change and confirmation of purchase.


def control_center():

#funBankAccount()

#funStoreItems()

funCashRegister()

control_center()









share|improve this question















closed as too broad by Mureinik, stovfl, Noctis Skytower, alexi2, EdChum Nov 21 at 9:48


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.















  • Please elaborate on what part of the code is not working. In Python you can just check a string with equality (==). So if you have a UPC and user input you could do, if UPC == db_string:
    – kstullich
    Nov 20 at 19:09










  • The code is working just fine. Sorry if I didn't specifically say the question right away but it's the bolded part that says "I am having trouble on finding ways on how to check the user's input to see if it matches the UPC(the ones that says 0001,0002,0003) in the database. Or long story short, how to check if a string matches a value from a table from a database."
    – Hmongster Moua
    Nov 20 at 22:40














-1












-1








-1







I am creating a cash register in one of my classes and our teacher wants us to input the Universal Postal Code(UPC). So far, I have created the table and inserted all of the products. Although there are twenty of them so i've only put three on here.



The thing I am having trouble with is on finding ways on how to check the user's input to see if it matches the UPC(the ones that says 0001,0002,0003) in the database. Or long story short, how to check if a string matches a value from a table from a database.



If you would like to see the entire coding to get a better idea, scroll down better



import sqlite3

c = conn.cursor()

c.execute('CREATE TABLE IF NOT EXISTS tblStoreItems(intUniversalProductCode
INT,strProductName TEXT,intQuantity INT,fltPrice REAL)')
conn.commit()

def funStoreItems():
c.execute("INSERT INTO
tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice)
VALUES(0001,'EGGS',421,3.5)")#1,473.5

c.execute("INSERT INTO
tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice)
VALUES(0002,'TURKEY',803,7.75)") #6,223.25

c.execute("INSERT INTO
tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice)
VALUES(0003,'HAM',921,7.25)") #6,720.75

#funStoreItems()
UPC = int(input("Please enter the UPC:"))




FULL CODE:



import sqlite3

print("Opened database successfully!")

c = conn.cursor()

c.execute('CREATE TABLE IF NOT EXISTS tblStoreItems(intUniversalProductCode INT,strProductName TEXT,intQuantity INT,fltPrice REAL)')
conn.commit()

def funStoreItems():
c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0001,'EGGS',421,3.5)")#1,473.5

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0002,'TURKEY',803,7.75)") #6,223.25

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0003,'HAM',921,7.25)") #6,720.75

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0004,'BREAD',212,4)") #848

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0005,'PANCAKE MIX',104,8)") #832

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0006,'CHEESE',742,2)") #1,484

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0007,'SAUSAGE',654,10)") #6,540

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0008,'CEREAL',1000,2)") #2,000

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0009,'MILK',1223,4.5)") #55053.5

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0010,'ORANGE JUICE',542,4)") #2,096

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0011,'SALAD',213,3)") #639

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0012,'ICE CREAM',666,5)") #3,330

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0013,'CHOCOLATE',1268,1)") #1,268

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0014,'CORN',364,3.75)") #1,365

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0015,'PASTA',196,6.75)")#1,323

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0016,'BANANA',150,4)") #600

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0017,'APPLE',407,4)") #1,628

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0018,'STEAK',545,15)") #8,175

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0019,'CARROT',312,2.5)") #802.5

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0020,'SUSHI',53,20)") #1,060

conn.commit()


def funBankAccount():
#103461.50
total_balance = float(103461.50)

wallet = print("nYour current balance is:",total_balance)

withdrawal = float(input("nHow much money would you like to draw from the bank?"))


if withdrawal > total_balance:
overload = input("nYou do not have enough to withdraw! would you just like to withdraw all of your money?").upper()

if overload == 'yes'.upper():
wallet = total_balance
print("You now have", wallet,"in your wallet.")

elif overload == 'no'.upper:
control_center()

#If the withdrawal amount is less than total balance
elif withdrawal < total_balance:
#Take away how much the user has inputted
total_balance = (total_balance - withdrawal)
#Withdraw the amount of money that the user withdrawed.
wallet = withdrawal
print("nYou now have",wallet,"in your wallet")
else:
print("Invalid! Please try again")
funBankAccount()

def funCashRegister():
print("n________________________________________________nHere are the list of things that you can buy:n==================================nItem: Eggs | UPC: 0001 nItem: Turkey | UPC: 0002 nItem: Ham | UPC: 0003 nItem: Bread | UPC: 0004 nItem: Pancake | UPC: 0005 nItem: Cheese | UPC: 0006 nItem: Sausage | UPC: 0007 nItem: Cereal | UPC: 0008 nItem: Milk | UPC: 0009 nItem: Orange Juice | UPC: 0010 nItem: Salad | UPC: 0011 nItem: Ice Cream | UPC: 0012 nItem: Chocolate | UPC: 0013 nItem: Corn | UPC: 0014 nItem: Pasta | UPC: 0015 nItem: Banana | UPC: 0016 nItem: Apple | UPC: 0017 nItem: Steak | UPC: 0018 nItem: Carrot | UPC: 0019 nItem: Sushi | UPC: 0020 n==================================")

#STEP 1)This will ask the user for the input of the UPC
#user_input_upc = int(input("nPlease enter the Universal Postal Code here for the produc tthat you are wanting to purchase today."))
UPC_or_Item = ""
UPC = int(input("Please enter the UPC:"))

#take out the numbers from the string and convert them into digits

#Otherwise if they don't type in digits then continue.



#Step 2) Retreiving Product description and price(database)
#Grab the item of the UPC then print it out telling the user how much they have to pay for it
#aaaa = float(input("How much did the customer pay you"))

#Search how to check if a string matches value in a table in a database in python

#OR check how I did that inside the password database.

#print("You have to pay", x,"before acquiring this.")


#Step 3)Give the cashier a way to signal that the transaction is complete. Afterwards, provide subtotal, tax, total cash tendered and calculate changes


#Step3.1) USE OWASSO TAX: 8.917%. Do the math

#Step3.2) Remove quantity and once it hits zero, tell the user that they can no longer purchase the item for it is out of stock.

#Step4) Print out the change and confirmation of purchase.


def control_center():

#funBankAccount()

#funStoreItems()

funCashRegister()

control_center()









share|improve this question















I am creating a cash register in one of my classes and our teacher wants us to input the Universal Postal Code(UPC). So far, I have created the table and inserted all of the products. Although there are twenty of them so i've only put three on here.



The thing I am having trouble with is on finding ways on how to check the user's input to see if it matches the UPC(the ones that says 0001,0002,0003) in the database. Or long story short, how to check if a string matches a value from a table from a database.



If you would like to see the entire coding to get a better idea, scroll down better



import sqlite3

c = conn.cursor()

c.execute('CREATE TABLE IF NOT EXISTS tblStoreItems(intUniversalProductCode
INT,strProductName TEXT,intQuantity INT,fltPrice REAL)')
conn.commit()

def funStoreItems():
c.execute("INSERT INTO
tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice)
VALUES(0001,'EGGS',421,3.5)")#1,473.5

c.execute("INSERT INTO
tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice)
VALUES(0002,'TURKEY',803,7.75)") #6,223.25

c.execute("INSERT INTO
tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice)
VALUES(0003,'HAM',921,7.25)") #6,720.75

#funStoreItems()
UPC = int(input("Please enter the UPC:"))




FULL CODE:



import sqlite3

print("Opened database successfully!")

c = conn.cursor()

c.execute('CREATE TABLE IF NOT EXISTS tblStoreItems(intUniversalProductCode INT,strProductName TEXT,intQuantity INT,fltPrice REAL)')
conn.commit()

def funStoreItems():
c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0001,'EGGS',421,3.5)")#1,473.5

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0002,'TURKEY',803,7.75)") #6,223.25

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0003,'HAM',921,7.25)") #6,720.75

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0004,'BREAD',212,4)") #848

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0005,'PANCAKE MIX',104,8)") #832

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0006,'CHEESE',742,2)") #1,484

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0007,'SAUSAGE',654,10)") #6,540

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0008,'CEREAL',1000,2)") #2,000

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0009,'MILK',1223,4.5)") #55053.5

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0010,'ORANGE JUICE',542,4)") #2,096

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0011,'SALAD',213,3)") #639

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0012,'ICE CREAM',666,5)") #3,330

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0013,'CHOCOLATE',1268,1)") #1,268

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0014,'CORN',364,3.75)") #1,365

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0015,'PASTA',196,6.75)")#1,323

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0016,'BANANA',150,4)") #600

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0017,'APPLE',407,4)") #1,628

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0018,'STEAK',545,15)") #8,175

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0019,'CARROT',312,2.5)") #802.5

c.execute("INSERT INTO tblStoreItems(intUniversalProductCode,strProductName,intQuantity,fltPrice) VALUES(0020,'SUSHI',53,20)") #1,060

conn.commit()


def funBankAccount():
#103461.50
total_balance = float(103461.50)

wallet = print("nYour current balance is:",total_balance)

withdrawal = float(input("nHow much money would you like to draw from the bank?"))


if withdrawal > total_balance:
overload = input("nYou do not have enough to withdraw! would you just like to withdraw all of your money?").upper()

if overload == 'yes'.upper():
wallet = total_balance
print("You now have", wallet,"in your wallet.")

elif overload == 'no'.upper:
control_center()

#If the withdrawal amount is less than total balance
elif withdrawal < total_balance:
#Take away how much the user has inputted
total_balance = (total_balance - withdrawal)
#Withdraw the amount of money that the user withdrawed.
wallet = withdrawal
print("nYou now have",wallet,"in your wallet")
else:
print("Invalid! Please try again")
funBankAccount()

def funCashRegister():
print("n________________________________________________nHere are the list of things that you can buy:n==================================nItem: Eggs | UPC: 0001 nItem: Turkey | UPC: 0002 nItem: Ham | UPC: 0003 nItem: Bread | UPC: 0004 nItem: Pancake | UPC: 0005 nItem: Cheese | UPC: 0006 nItem: Sausage | UPC: 0007 nItem: Cereal | UPC: 0008 nItem: Milk | UPC: 0009 nItem: Orange Juice | UPC: 0010 nItem: Salad | UPC: 0011 nItem: Ice Cream | UPC: 0012 nItem: Chocolate | UPC: 0013 nItem: Corn | UPC: 0014 nItem: Pasta | UPC: 0015 nItem: Banana | UPC: 0016 nItem: Apple | UPC: 0017 nItem: Steak | UPC: 0018 nItem: Carrot | UPC: 0019 nItem: Sushi | UPC: 0020 n==================================")

#STEP 1)This will ask the user for the input of the UPC
#user_input_upc = int(input("nPlease enter the Universal Postal Code here for the produc tthat you are wanting to purchase today."))
UPC_or_Item = ""
UPC = int(input("Please enter the UPC:"))

#take out the numbers from the string and convert them into digits

#Otherwise if they don't type in digits then continue.



#Step 2) Retreiving Product description and price(database)
#Grab the item of the UPC then print it out telling the user how much they have to pay for it
#aaaa = float(input("How much did the customer pay you"))

#Search how to check if a string matches value in a table in a database in python

#OR check how I did that inside the password database.

#print("You have to pay", x,"before acquiring this.")


#Step 3)Give the cashier a way to signal that the transaction is complete. Afterwards, provide subtotal, tax, total cash tendered and calculate changes


#Step3.1) USE OWASSO TAX: 8.917%. Do the math

#Step3.2) Remove quantity and once it hits zero, tell the user that they can no longer purchase the item for it is out of stock.

#Step4) Print out the change and confirmation of purchase.


def control_center():

#funBankAccount()

#funStoreItems()

funCashRegister()

control_center()






python database string python-3.x sqlite3






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 22:51

























asked Nov 20 at 19:05









Hmongster Moua

53




53




closed as too broad by Mureinik, stovfl, Noctis Skytower, alexi2, EdChum Nov 21 at 9:48


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.






closed as too broad by Mureinik, stovfl, Noctis Skytower, alexi2, EdChum Nov 21 at 9:48


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.














  • Please elaborate on what part of the code is not working. In Python you can just check a string with equality (==). So if you have a UPC and user input you could do, if UPC == db_string:
    – kstullich
    Nov 20 at 19:09










  • The code is working just fine. Sorry if I didn't specifically say the question right away but it's the bolded part that says "I am having trouble on finding ways on how to check the user's input to see if it matches the UPC(the ones that says 0001,0002,0003) in the database. Or long story short, how to check if a string matches a value from a table from a database."
    – Hmongster Moua
    Nov 20 at 22:40


















  • Please elaborate on what part of the code is not working. In Python you can just check a string with equality (==). So if you have a UPC and user input you could do, if UPC == db_string:
    – kstullich
    Nov 20 at 19:09










  • The code is working just fine. Sorry if I didn't specifically say the question right away but it's the bolded part that says "I am having trouble on finding ways on how to check the user's input to see if it matches the UPC(the ones that says 0001,0002,0003) in the database. Or long story short, how to check if a string matches a value from a table from a database."
    – Hmongster Moua
    Nov 20 at 22:40
















Please elaborate on what part of the code is not working. In Python you can just check a string with equality (==). So if you have a UPC and user input you could do, if UPC == db_string:
– kstullich
Nov 20 at 19:09




Please elaborate on what part of the code is not working. In Python you can just check a string with equality (==). So if you have a UPC and user input you could do, if UPC == db_string:
– kstullich
Nov 20 at 19:09












The code is working just fine. Sorry if I didn't specifically say the question right away but it's the bolded part that says "I am having trouble on finding ways on how to check the user's input to see if it matches the UPC(the ones that says 0001,0002,0003) in the database. Or long story short, how to check if a string matches a value from a table from a database."
– Hmongster Moua
Nov 20 at 22:40




The code is working just fine. Sorry if I didn't specifically say the question right away but it's the bolded part that says "I am having trouble on finding ways on how to check the user's input to see if it matches the UPC(the ones that says 0001,0002,0003) in the database. Or long story short, how to check if a string matches a value from a table from a database."
– Hmongster Moua
Nov 20 at 22:40












1 Answer
1






active

oldest

votes


















0














You can achieve it using SQL itself. WHERE condition could help you.



if c.execute("select * from tblStoreItems where intUniversalProductCode="+str(upc)) is None:
#When there is no entry for the upc, the query hits the DB and brings nothing. so, this if condition gets executed.
print("Sorry, we dont have such an entry!!")
else:
#when the query returns an output it means, there is an entry for the upc
for item in c.execute("select * from tblStoreItems where intUniversalProductCode="+str(upc)):
print(item)


Output:



(1, 'EGGS', 421, 3.5)






share|improve this answer




























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    You can achieve it using SQL itself. WHERE condition could help you.



    if c.execute("select * from tblStoreItems where intUniversalProductCode="+str(upc)) is None:
    #When there is no entry for the upc, the query hits the DB and brings nothing. so, this if condition gets executed.
    print("Sorry, we dont have such an entry!!")
    else:
    #when the query returns an output it means, there is an entry for the upc
    for item in c.execute("select * from tblStoreItems where intUniversalProductCode="+str(upc)):
    print(item)


    Output:



    (1, 'EGGS', 421, 3.5)






    share|improve this answer


























      0














      You can achieve it using SQL itself. WHERE condition could help you.



      if c.execute("select * from tblStoreItems where intUniversalProductCode="+str(upc)) is None:
      #When there is no entry for the upc, the query hits the DB and brings nothing. so, this if condition gets executed.
      print("Sorry, we dont have such an entry!!")
      else:
      #when the query returns an output it means, there is an entry for the upc
      for item in c.execute("select * from tblStoreItems where intUniversalProductCode="+str(upc)):
      print(item)


      Output:



      (1, 'EGGS', 421, 3.5)






      share|improve this answer
























        0












        0








        0






        You can achieve it using SQL itself. WHERE condition could help you.



        if c.execute("select * from tblStoreItems where intUniversalProductCode="+str(upc)) is None:
        #When there is no entry for the upc, the query hits the DB and brings nothing. so, this if condition gets executed.
        print("Sorry, we dont have such an entry!!")
        else:
        #when the query returns an output it means, there is an entry for the upc
        for item in c.execute("select * from tblStoreItems where intUniversalProductCode="+str(upc)):
        print(item)


        Output:



        (1, 'EGGS', 421, 3.5)






        share|improve this answer












        You can achieve it using SQL itself. WHERE condition could help you.



        if c.execute("select * from tblStoreItems where intUniversalProductCode="+str(upc)) is None:
        #When there is no entry for the upc, the query hits the DB and brings nothing. so, this if condition gets executed.
        print("Sorry, we dont have such an entry!!")
        else:
        #when the query returns an output it means, there is an entry for the upc
        for item in c.execute("select * from tblStoreItems where intUniversalProductCode="+str(upc)):
        print(item)


        Output:



        (1, 'EGGS', 421, 3.5)







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 20 at 19:22









        Jim Todd

        24716




        24716















            Popular posts from this blog

            Feedback on college project

            Futebolista

            Albești (Vaslui)