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


from math import *
from random import *


class Vegetable:

    def __init__(self, nazvanie='', ves=0.0, vitamin_c=0.0):
        self.nazvanie = nazvanie
        self.ves = ves
        self.vitamin_c = vitamin_c

    def summa_vesa(self, other):
        return self.ves + other.ves

    def __gt__(self, other):
        return self.vitamin_c > other.vitamin_c

    def __lt__(self, other):
        return self.vitamin_c < other.vitamin_c

    def __eq__(self, other):
        return self.vitamin_c == other.vitamin_c

    def __str__(self):
        return f'{self.nazvanie}: вес {self.ves} г, витамин C {self.vitamin_c} мг на 100 г'

    def kolvo_vitamina(self):
        return self.ves / 100 * self.vitamin_c


def max_vitamin(spisok):
    maks = spisok[0]
    for elem in spisok:
        if elem > maks:
            maks = elem
    return maks


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

ov1 = Vegetable('Перец', 150, 200)
ov2 = Vegetable('Огурец', 200, 10)

print('Первый овощ: ', ov1)
print('Второй овощ: ', ov2)

print('\nСуммарный вес:', ov1.summa_vesa(ov2), 'г')

print('\nСравнение по витамину C:')
print('ov1 > ov2:', ov1 > ov2)
print('ov1 < ov2:', ov1 < ov2)
print('ov1 == ov2:', ov1 == ov2)

print('\nВитамина C с учётом веса:')
print(f'{ov1.nazvanie}: {ov1.kolvo_vitamina():.2f} мг')
print(f'{ov2.nazvanie}: {ov2.kolvo_vitamina():.2f} мг')

spisok = [ov1, ov2, Vegetable('Капуста', 300, 45)]
print('\nОвощ с максимальным витамином C:')
print(max_vitamin(spisok))