Код: Выделить всё
----- Welcome to my checkout! -----
Please enter the barcode of your item: 123
Milk, 2 Litres - $2.0
Would you like to scan another product? (Y/N) y
Please enter the barcode of your item: 456
Bread - $3.5
Would you like to scan another product? (Y/N) y
Please enter the barcode of your item: 999
This product does not exist in our inventory.
Would you like to scan another product? (Y/N) n
Payment due: $5.5. Please enter an amount to pay: 5
Payment due: $0.5. Please enter an amount to pay: -3
We don't accept negative money!
Payment due: $0.5. Please enter an amount to pay: 2
----- Final Receipt -----
Milk, 2 Litres $2.0
Bread $3.5
Total amount due: $5.5
Amount received: $7.0
Change given: $1.5
Thank you for shopping at mytsore!
(N)ext customer, or (Q)uit? q
Код: Выделить всё
items = {'banana': {'price': 4, 'stock': 6, 'code':123 },
'apple': {'price': 2, 'stock': 0,'code':1231 },
'orange': {'price': 1.5, 'stock': 32,'code':1233},
'pear': {'price': 3, 'stock': 15,'code':12335},
}
bar=int(input("enter barcode:"))
sum = 0
price =[]
products =[]
for key in items:
if items[key]['code'] == int(bar):
print("item found")
print (key)
print ("price: %s" % items[key]['price'])
print ("stock: %s" % items[key]['stock'])
print ("Barcode: %s" % items[key]['code'])
price.append(items[key]['price'])
products.append(key)
print(price)
print(products)
print("..............................................")
while True:
choice = input("scan another item?y/n")
if choice =='n':
for cost in price:
sum += cost
print("Total cost:",sum)
print("..............................................")
if choice =='y':
bar=int(input("enter barcode:"))
for key in items:
if items[key]['code'] == int(bar):
print("item found")
print (key)
print ("price: %s" % items[key]['price'])
print ("stock: %s" % items[key]['stock'])
print ("Barcode: %s" % items[key]['code'])
price.append(items[key]['price'])
products.append(key)
#print(price)
Подробнее здесь: https://stackoverflow.com/questions/500 ... ith-python
Мобильная версия