Я был в этом в течение нескольких дней. Мне нужно иметь возможность возвращать в корзину список товаров, которые пользователь купил раньше. Я не знаю что делать!
items = [('diapers', 10.00), ('peanuts', 5.00), ('butter', 6.25), ('cheese',
3.00), ('milk', 3.5), ('yogurt', 1.99), ('eggs', 4.5), ('bread', 4),
('shrimp', 2.5), ('coffee', 1.5)]
money = 50
ask = ('buy', 'return', 'quit')
cartList = []
while ask != 'quit':
print("""
Diapers ....10.00
Peanuts ....5.00
Butter .....6.25
Cheese .....3.00
Milk .......3.50
Yogurt .....1.99
Eggs .......4.50
Bread ......4.00
Shrimp .....2.50
Coffee .....1.50
""")
ask = input('Do you want to buy, return or quit?\n').lower()
if ask == 'buy':
item = input('\nWhat item do you need?\n').lower()
for i in items:
if item == i[0]:
print(item, 'is $', i[1])
ques = input('\nDo you want to buy this item?
[Y:N]\n').lower()
if i[1] > money:
print('You do not have enough money for this item :(\n')
break
if ques == 'n':
print('Sorry that you do not want that item :(')
break
if ques == 'y':
money = money - i[1]
print('\nYou now have $', money)
cartList.insert(0, item)
print('You have these items in your cart:\n', cartList,
'\n')
else:
print('You entered an incorrect value :(')
if ask == 'return':
ret = input('What item do you want to return?\n')
for i in cartList:
if ret == i[0]:
print(i[0], '$', i[1])
quest = input('Do you want to return this item?
[Y:N]]\n').lower()
else:
print('This item is not in your cart!\n')
print('\nThank you for shopping with us!')
Там, где есть спрос = возврат, мне нужно, чтобы пользователь мог вернуть купленный товар. Я пытался сделать несколько попыток, чтобы пользователь мог вернуть товар.