I am creating a python stock system in ,which I need to allow a user to enter a product code and enter their quantity and the software checks a txt file. It checks whether the product is found and whether their is enough of them. I am stuck trying to make my code subtract the quantity needed from the total quantity in the text file. I only want to change the quantity of that one product. Any help will be appreciated. Thanks Ben
Edit:
I have to use txt as it is part of the design brief.
x = 10
y = 0
n = 1
data = [line.strip().split() for line in open("Untitled.txt")]
code = input("Please enter Product Code?")
quantity = input("How many of these do you need?")
for num in range(0,10):
if data[x][0] == code:
n = 0
y = x
x = x - 1
if n == 0:
if data[y][3] >= quantity:
print("Product in stock")
old = int(data [y][3])
quantity = int(quantity)
new = old - quantity
new = str(new)
data[y][3] = new
else:
print("Product out of stock")
else:
print("Product not found")
This is my txt file
Code Description Price Quantity
12345670 testitem 1.45 34
12345671 testitem 1.45 34
12345672 testitem 1.45 34
12345673 testitem 1.45 34
12345674 testitem 1.45 34
12345675 testitem 1.45 34
12345676 testitem 1.45 34
12345677 testitem 1.45 34
12345678 testitem 1.45 34
12345679 testitem 1.45 34
12345680 testitem 1.45 34