I'm trying to create a program that generates estimates to potential customers. The idea is that you enter item-Ids and quantities of wanted item/s and the program goes through a database to find and extract matching values, if any.
In the case that there is no match, I want to be able to manually add the details (for the current calculation, not write to database )
I got it all working, if the manual process is made at the very end. But since you wouldn't know if an item exists or not beforehand, it's easy to break the program.
I've tried to look all over for a solution before writing this but haven't been able to. My guess is that I don't fully understand the order of things and/or is missing some basic function to make it work.
The closest I was of finding an explanation was, as I understood it, to somehow create separate functions for the if/else statements and call them separately when appropriate, but I don't know how to implement that in the existing code.
Here's a snippet from the code:
#TRY TO FIND ITEM IN FILE
while totalItems != 0:
article = input("Search: ")
totalItems = totalItems - 1
for row in csv_file:
if article == row[0]:
items.append(row[0])
desc.append(row[1])
prices.append(float(row[2]))
qt = input("Quantity: ")
qt = int(qt)
qts.append(qt)
break
if article != row[0]:
items.append(article)
qt = input("Quantity: ")
qt = int(qt)
qts.append(qt)
inputItem = input("Item: ")
desc.append(inputItem)
inputPrice = input("Price: ")
inputPrice = float(inputPrice)
prices.append(inputPrice)
Example snippet if all items exists in database/file:
Search: 1821091
Quantity: 5
Search: 1835006
Quantity: 5
Search: 1835017
Quantity: 5
How many % profit?:
Example snippet if last item does not exist:
Search: 1821091
Quantity: 5
Search: 1835006
Quantity: 5
Search: 0000000
Quantity: 5
Item: Bogus-Product
Price: 80.40
How many % profit?:
Example snippet if item that does not exist is added anywhere before last entry:
Search: 0000000
Quantity: 5
Item: Bogus-Product
Price: 80.40
Search: 1821091
Quantity: 5
Item: < This should not ask me to add another item...
Aucun commentaire:
Enregistrer un commentaire