Created
March 28, 2021 10:39
-
-
Save svsq/9bf43e182154a3774d9b78f86c7cc958 to your computer and use it in GitHub Desktop.
Goods in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from Tovar import * | |
tovari = [ | |
Tovar("Хлеб", 9, 20), | |
Tovar("Молоко", 3, 29), | |
Tovar("Чай", 6, 45), | |
Tovar("Кефир", 8, 37), | |
Tovar("Конфеты", 5, 120), | |
] | |
def print_all_goods(): | |
c = 1 | |
for i in tovari: | |
print("%s) %s - %d шт. по %d грн, итого: %d грн" % ( | |
c, i.name, i.count, i.price, i.total_price)) | |
c += 1 | |
def print_not_found(): | |
print("Товар не найден") | |
print_all_goods() | |
while 1: | |
n = input('Введите имя товара(\'+\' добавить, \'-\' удалить, = посмотреть): ') | |
if n == '0': | |
break | |
elif n == '+': | |
print("Режим добавления товара.") | |
name = input("Название товара: ").capitalize() | |
count = int(input("Количество: ")) | |
price = int(input("Стоимость за 1 шт: ")) | |
found = False | |
index = 0 | |
for i in tovari: | |
if i.name == name.capitalize(): | |
found = True | |
index = tovari.index(i) | |
if not found: | |
tovari.append(Tovar(name, count, price)) # Добавление нового товара в конец массива | |
else: | |
tovari[index] = Tovar(name, count, price) # Заменяем старый товар новым | |
elif n == '-': | |
print("Режим удаления товара.") | |
name = input("Название товара: ") | |
found = False | |
for i in tovari: | |
if i.name == name.capitalize(): | |
tovari.remove(i) # Удаляем товар из массива | |
found = True | |
if not found: | |
print_not_found() | |
elif n == '=': | |
print_all_goods() | |
else: | |
found = False | |
for i in tovari: | |
if i.name == n.capitalize(): | |
i.count = int(input('Количество: ')) | |
i.update_total_price() | |
found = True | |
if not found: | |
print_not_found() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment