'Python-POS machine to generate bill and inventory management
I am new to python, I am doing a pos machine that can genarate the bill and inventory management for my school assignment . I had no idea why my input for the product id will only generate twice but not continuosly until the input is 0 for the payment. Other than that, why when the bill is print out there is no product name and the price will be zero only?
this my item list
all_products = [
[1, "Razer Deathadder V2 Pro" , 100, 349.00],
[2, "Razer Viper Ultimate", 105, 419.00],
[3, "Razer Basilink Ultimate" , 35, 599.00],
[4, "Razer Viper mini", 295, 139.00],
[5, "Razer Deathadder X", 592, 76.90]
]
function to generate bill
def generate_bill(product, price, lst):
print("-" * 40)
print("\t\tRazer Mouse Shop")
print("-" * 40)
print("Bill:{} \tDate:{}".format(int(random.random()*100000), str(datetime.now())))
print("Product name\t\tprice")
print("-" * 40)
for j in range(len(lst)):
print("{}\t\tRM{}".format(j , item[-1]))
print("-" * 40)
print("\t\tTotal Bill Amount: {}".format(price))
The code when i choose to generate bill
elif choice == 2:
display_all()
print("Press 0 for payment")
item_lst = []
total_price = 0
prod_id = int(input("Enter the Product ID: "))
while prod_id != 0:
prod_id = int(input("Enter the Product ID: "))
for item in all_products:
if item[0] == prod_id:
item_lst.append(item[0])
total_price = total_price + item[2]
if item[1] == 0:
print("Sorry we are out of stock")
else:
item[1] -= 1
member = input("Do you have membership(Y/N): ")
if member == "Y":
total_price * 0.9
generate_bill(item, total_price, item_lst)
print("Thanks For shopping with Us")
sys.exit(0)
else:
print("Continue Shopping")
The output

click this the whole code at here
I had tried to change the totalprice += item[2] to totalprice = totalprice + item[2] in the while loop there, remove the prodid = int(input("Enter the Product ID: ")) from the while loops. But the output just the same, totalprice = 0 and the input for the prod_id just come out one time, not continuosly until i input 0.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
