Форум сайта python.su
0
Вот код программы
def fruits(): for item2 in products_fruits: print(item2, end="\n") def vegetables(): for item3 in products_vegetables: print(item3, end="\n") def chancelleries(): for item4 in products_chancelleries: print(item4, end="\n") print ("Добро пожаловать в Магазин продуктов!") print("Выберите себе продукты: ", end='\n') category = ["Фрукты", "Овощи", "Канцелярия"] products_fruits = ["Бананы", "Яблоки", "Груши", "Апельсины", "Мандарины"] products_vegetables = ["Капуста", "Картошка", "Морковь", "Помидоры", "Огурцы"] products_chancelleries = ["Ручки", "Тетради", "Карандаши", "Фломастреы", "Пластилин"] shoplist = [] shop = True while shop: for item in category: print(item, end="\n") print("Если желаете закончить покупки, нажмите 'q'") takecategory = input("Выберите категорию: ") if takecategory == "1": fruits() fruit = True while fruit: print("Если желаете вернуться в Категории, нажмите 'q'") takefruits = input("Выберите фрукты: ") if takefruits == "1": shoplist.append(products_fruits[0]) elif takefruits == "2": shoplist.append(products_fruits[1]) elif takefruits == "3": shoplist.append(products_fruits[2]) elif takefruits == "4": shoplist.append(products_fruits[3]) elif takefruits == "5": shoplist.append(products_fruits[4]) elif takefruits == "q": fruit = False else: print("Такого фрукта в списке нет!") print("В вашей корзине" + str(shoplist), end="\n\n") elif takecategory == "2": vegetables() vegetable = True while vegetable: print("Если желаете вернуться в Категории, нажмите 'q'") takevegetables = input("Выберите овощи: ") if takevegetables == "1": shoplist.append(products_vegetables[0]) elif takevegetables == "2": shoplist.append(products_vegetables[1]) elif takevegetables == "3": shoplist.append(products_vegetables[2]) elif takevegetables == "4": shoplist.append(products_vegetables[3]) elif takevegetables == "5": shoplist.append(products_vegetables[4]) elif takevegetables == "q": vegetable = False else: print("Таких овощей в списке нет!") print("В вашей корзине" + str(shoplist), end="\n\n") elif takecategory == "3": chancelleries() chancellery = True while chancellery: print("Если желаете вернуться в Категории, нажмите 'q'") takechancelleries = input("Выберите канцелярский товар: ") if takechancelleries == "1": shoplist.append(products_chancelleries[0]) elif takechancelleries == "2": shoplist.append(products_chancelleries[1]) elif takechancelleries == "3": shoplist.append(products_chancelleries[2]) elif takechancelleries == "4": shoplist.append(products_chancelleries[3]) elif takechancelleries == "5": shoplist.append(products_chancelleries[4]) elif takechancelleries == "q": chancellery = False else: print("Такого канцелярского товара в списке нет!") print("В вашей корзине" + str(shoplist), end="\n\n") elif takecategory == "q": shop = False else: print("Такой Категории в списке нет!") print("Вы купили: ", shoplist, end="\n\n") print("Спасибо за покупки!")
Отредактировано eDn1 (Фев. 21, 2021 18:13:00)
Офлайн
124
eDn1Вопрос не понятен, давайте подробнее на пальцах с примерами,или другими словами, что у вас на входе, и что хотите получить на выходе
Подскажите пожалуйста, как присвоить значение(число) к ячейкам списка?
Офлайн
857
def fruits(): for number, item in enumerate(products_fruits, 1): print(number, item, end="\n") def vegetables(): for number, item in enumerate(products_vegetables, 1): print(number, item, end="\n") def chancelleries(): for number, item in enumerate(products_chancelleries, 1): print(number, item, end="\n") print ("Добро пожаловать в Магазин продуктов!") print("Выберите себе продукты: ", end='\n') category = ["Фрукты", "Овощи", "Канцелярия"] products_fruits = ["Бананы", "Яблоки", "Груши", "Апельсины", "Мандарины"] products_vegetables = ["Капуста", "Картошка", "Морковь", "Помидоры", "Огурцы"] products_chancelleries = ["Ручки", "Тетради", "Карандаши", "Фломастреы", "Пластилин"] shoplist = [] shop = True while shop: for number, item in enumerate(category, 1): print(number, item, end="\n") print("Если желаете закончить покупки, нажмите 'q'") takecategory = input("Выберите категорию: ") if takecategory == "1": fruits() fruit = True while fruit: print("Если желаете вернуться в Категории, нажмите 'q'") takefruits = input("Выберите фрукты: ") if takefruits == "1": shoplist.append(products_fruits[0]) elif takefruits == "2": shoplist.append(products_fruits[1]) elif takefruits == "3": shoplist.append(products_fruits[2]) elif takefruits == "4": shoplist.append(products_fruits[3]) elif takefruits == "5": shoplist.append(products_fruits[4]) elif takefruits == "q": fruit = False else: print("Такого фрукта в списке нет!") print("В вашей корзине" + str(shoplist), end="\n\n") elif takecategory == "2": vegetables() vegetable = True while vegetable: print("Если желаете вернуться в Категории, нажмите 'q'") takevegetables = input("Выберите овощи: ") if takevegetables == "1": shoplist.append(products_vegetables[0]) elif takevegetables == "2": shoplist.append(products_vegetables[1]) elif takevegetables == "3": shoplist.append(products_vegetables[2]) elif takevegetables == "4": shoplist.append(products_vegetables[3]) elif takevegetables == "5": shoplist.append(products_vegetables[4]) elif takevegetables == "q": vegetable = False else: print("Таких овощей в списке нет!") print("В вашей корзине" + str(shoplist), end="\n\n") elif takecategory == "3": chancelleries() chancellery = True while chancellery: print("Если желаете вернуться в Категории, нажмите 'q'") takechancelleries = input("Выберите канцелярский товар: ") if takechancelleries == "1": shoplist.append(products_chancelleries[0]) elif takechancelleries == "2": shoplist.append(products_chancelleries[1]) elif takechancelleries == "3": shoplist.append(products_chancelleries[2]) elif takechancelleries == "4": shoplist.append(products_chancelleries[3]) elif takechancelleries == "5": shoplist.append(products_chancelleries[4]) elif takechancelleries == "q": chancellery = False else: print("Такого канцелярского товара в списке нет!") print("В вашей корзине" + str(shoplist), end="\n\n") elif takecategory == "q": shop = False else: print("Такой Категории в списке нет!") print("Вы купили: ", shoplist, end="\n\n") print("Спасибо за покупки!")
Добро пожаловать в Магазин продуктов!
Выберите себе продукты:
1 Фрукты
2 Овощи
3 Канцелярия
Если желаете закончить покупки, нажмите 'q'
Выберите категорию: 1
1 Бананы
2 Яблоки
3 Груши
4 Апельсины
5 Мандарины
Если желаете вернуться в Категории, нажмите 'q'
Выберите фрукты: 1
В вашей корзине['Бананы']
Если желаете вернуться в Категории, нажмите 'q'
Выберите фрукты: 2
В вашей корзине['Бананы', 'Яблоки']
Если желаете вернуться в Категории, нажмите 'q'
Выберите фрукты: q
В вашей корзине['Бананы', 'Яблоки']
Вы купили: ['Бананы', 'Яблоки']
1 Фрукты
2 Овощи
3 Канцелярия
Если желаете закончить покупки, нажмите 'q'
Выберите категорию: q
Вы купили: ['Бананы', 'Яблоки']
Спасибо за покупки!
Офлайн
0
xam1816Я хочу узнать, как допустим присвоить цену на продукты которые хранятся в этих ячейках
products_fruits = ["Бананы", "Яблоки", "Груши", "Апельсины", "Мандарины"] products_vegetables = ["Капуста", "Картошка", "Морковь", "Помидоры", "Огурцы"] products_chancelleries = ["Ручки", "Тетради", "Карандаши", "Фломастреы", "Пластилин"]
Офлайн
44
eDn1тогда не понятно зачем вы выбрали list a не dict
Я хочу узнать, как допустим присвоить цену на продукты которые хранятся в этих ячейках
products_fruits = {"Бананы": 80, "Яблоки": 120, "Груши": 240, "Апельсины": None, "Мандарины": 1200}
и вставьте ссылку на его url Офлайн