Касса в супермаркете с PythonPython

Программы на Python
Ответить
Anonymous
 Касса в супермаркете с Python

Сообщение Anonymous »

Здравствуйте, я новичок в программировании на Python. Я только начал изучать Python. Мне нужна идея/частичный код о том, как создать следующую программу. Любая идея ценится. Мне нужно получить следующий результат.

Код: Выделить всё

----- 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)
если пользователь выбирает «n», программа должна остановиться и сгенерировать счета/квитанцию ​​с ценой. Даже я нажимаю опции «n», я все равно получаю сообщение «сканировать другой элемент? да/нет»)». Как мне структурировать свой код, чтобы результат был ниже ожидаемого? Я хочу обернуть свой код внутри функций и создать экземпляр, используя концепцию ООП

Подробнее здесь: https://stackoverflow.com/questions/500 ... ith-python
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Python»