Загрузка данных


from math import *
from random import *


class Product:

    def __init__(self):
        self.title = ''
        self.cost = 0.0
        self.count = 0

    def set(self):
        self.title = input("Введите название товара ")
        self.cost = float(input("Введите цену "))
        self.count = int(input("Введите количество "))

    def __str__(self):
        s = self.count * self.cost
        return f"{self.title} {self.cost}руб.*{self.count}шт.={s}руб."


class Shop:

    def __init__(self):
        self.name = ''
        self.list = []
        self.size = 0

    def set(self):
        self.name = input("Введите название магазина ")
        self.size = int(input("Введите количество товаров "))
        for i in range(self.size):
            t = Product()
            print("-" * 20, i + 1, "товар", "-" * 20)
            t.set()
            self.list.append([t.title, t.cost, t.count])
        print("Создание списка товара магазина прошло успешно...")

    def __str__(self):
        print(f"\nСписок товаров магазина {self.name}:")
        return '\n'.join(f"{self.list[i][0]} {self.list[i][1]}руб.*{self.list[i][2]}шт.={self.list[i][1] * self.list[i][2]}руб." for i in range(self.size))

    def append(self, title, cost, count):
        self.list.append([title, cost, count])
        self.size += 1
        print("Добавление прошло успешно...")

    def __delitem__(self, title):
        i = 0
        k = 0
        while i < len(self.list):
            if self.list[i][0] == str(title):
                del self.list[i]
                self.size -= 1
                k += 1
            else:
                i += 1
        if k != 0:
            print("Удаление прошло успешно. Удалены", k, "товаров")
        else:
            print("Удаление не выполнено. Товаров с названием", str(title), "нет")

    def __getitem__(self, title):
        temp = [self.list[i][0] for i in range(self.size)]
        if str(title) in temp:
            number = temp.index(str(title))
            return self.list[number]
        else:
            return "Товара с названием " + str(title) + " нет"

    def __len__(self):
        return len(self.list)

    def __pos__(self):
        temp = [self.list[i][1] * self.list[i][2] for i in range(len(self.list))]
        return sum(temp)

    def __lt__(self, other):
        return +self < +other

    def __gt__(self, other):
        return +self > +other

    def __eq__(self, other):
        return +self == +other

    def min_stoimost(self):
        temp = [self.list[i][1] * self.list[i][2] for i in range(len(self.list))]
        return min(temp)

    def __mul__(self, other):
        rez = Shop()
        rez.name = self.name
        rez.size = self.size
        rez.list = [[elem[0], round(elem[1] * (1 + other / 100), 2), elem[2]] for elem in self.list]
        return rez

    def __rmul__(self, other):
        return self.__mul__(other)


print("\n+" + "-" * 35 + "+")
print("| {:<33} |".format("Выполнил: Пикун Дмитрий"))
print("| {:<33} |".format("Группа:   ИСП-2024"))
print("| {:<33} |".format("Вариант:  №"))
print("+" + "-" * 35 + "+\n")

s = Shop()
s.set()
print("Начальные данные: \n", s)

s.append("rabbit", 260, 1)
s.append("house", 500, 3)
print("-" * 50)
print(s)

t1 = input("Введите название для удаления ")
del s[t1]
print(s)

t2 = input("Введите название для поиска ")
print(s[t2])

print("В магазине ", len(s), "товаров")
print("Общая стоимость товаров в магазине=", +s)

print("Наименьшая стоимость товара=", s.min_stoimost())

s2 = Shop()
s2.name = "Второй"
s2.append("cat", 100, 2)
s2.append("fish", 50, 4)
print(s2)

print("\ns > s2:", s > s2)
print("s < s2:", s < s2)
print("s == s2:", s == s2)

s3 = s * 10
print("\nЦены повышены на 10% (s * 10):")
print(s3)

s4 = 10 * s
print("\nЦены повышены на 10% (10 * s):")
print(s4)