Исанбеков Дамир 414 КФ CyberSausage 11229
Швец Игорь Станиславович 411 Казахстанский филиал CyberSausage 11088
f1from fractions import Fractionf1from fractions import Fraction
22
3class Sausage:3class Sausage:
44
n5    def __init__(self, ground='pork!', volume=1):n5    def __init__(self, stuffing='pork!', volume=1):
6        self.ground = ground6        self.stuffing = stuffing
7        self.volume = Fraction(volume)7        self.volume = Fraction(volume)
88
9    def __abs__(self):9    def __abs__(self):
10        return self.volume10        return self.volume
1111
12    def __add__(self, other):12    def __add__(self, other):
n13        return Sausage(self.ground, self.volume + other.volume)n13        return Sausage(self.stuffing, self.volume + other.volume)
1414
15    def __sub__(self, other):15    def __sub__(self, other):
n16        return Sausage(self.ground, max(self.volume - other.volume, 0))n16        return Sausage(self.stuffing, max(self.volume - other.volume, 0)
 >)
1717
18    def __mul__(self, factor):18    def __mul__(self, factor):
n19        return Sausage(self.ground, self.volume * factor)n19        return Sausage(self.stuffing, self.volume * factor)
2020
21    def __rmul__(self, factor):21    def __rmul__(self, factor):
22        return self * factor22        return self * factor
2323
24    def __truediv__(self, divisor):24    def __truediv__(self, divisor):
n25        return Sausage(self.ground, self.volume / divisor)n25        return Sausage(self.stuffing, self.volume / divisor)
2626
27    def __bool__(self):27    def __bool__(self):
28        return self.volume > 028        return self.volume > 0
2929
30    def __str__(self):30    def __str__(self):
31        if self.volume == 0:31        if self.volume == 0:
32            return '/|\n||\n||\n||\n\\|'32            return '/|\n||\n||\n||\n\\|'
33        full_loafs = int(self.volume)33        full_loafs = int(self.volume)
n34        remaining_fraction = self.volume - full_loafsn34        remainder = self.volume - full_loafs
35        top_border, ground_line, bottom_border = ('', '', '')35        str1, str2, str3 = ('', '', '')
36        for _ in range(full_loafs):36        for _ in range(full_loafs):
n37            a, b, c = self._create_full_loaf()n37            a, b, c = self._full_loaf()
38            top_border += a38            str1 += a
39            ground_line += b39            str2 += b
40            bottom_border += c40            str3 += c
41        if remaining_fraction > 0:41        if remainder > 0:
42            a, b, c = self._create_partial_loaf(remaining_fraction)42            a, b, c = self._partial_loaf(remainder)
43            top_border += a43            str1 += a
44            ground_line += b44            str2 += b
45            bottom_border += c45            str3 += c
46        return top_border + '\n' + (ground_line + '\n') * 3 + bottom_bor46        return str1 + '\n' + (str2 + '\n') * 3 + str3
>der 
4747
n48    def _create_full_loaf(self):n48    def _full_loaf(self):
49        ground_remainder = 12 % len(self.ground)49        remain = 12 % len(self.stuffing)
50        ground_main = 12 // len(self.ground)50        main = 12 // len(self.stuffing)
51        top_border = '/------------\\'51        border1 = '/------------\\'
52        ground_line = f'|{self.ground * ground_main + self.ground[:groun52        filling = f'|{self.stuffing * main + self.stuffing[:remain]}|'
>d_remainder]}|' 
53        bottom_border = '\\------------/'53        border2 = '\\------------/'
54        return (top_border, ground_line, bottom_border)54        return (border1, filling, border2)
5555
t56    def _create_partial_loaf(self, fraction):t56    def _partial_loaf(self, fraction):
57        total_ground_length = fraction.numerator * (12 // fraction.denom57        len_of_remain = fraction.numerator * (12 // fraction.denominator
>inator)>)
58        ground_count = total_ground_length // len(self.ground)58        count_of_word = len_of_remain // len(self.stuffing)
59        leftover_ground_length = total_ground_length - ground_count * le59        len_of_rest_word = len_of_remain - count_of_word * len(self.stuf
>n(self.ground)>fing)
60        top_border = '/' + '-' * total_ground_length + '|'60        border1 = '/' + '-' * len_of_remain + '|'
61        ground_line = f'|{self.ground * ground_count + self.ground[:left61        filling = f'|{self.stuffing * count_of_word + self.stuffing[:len
>over_ground_length]}|'>_of_rest_word]}|'
62        bottom_border = '\\' + '-' * total_ground_length + '|'62        border2 = '\\' + '-' * len_of_remain + '|'
63        return (top_border, ground_line, bottom_border)63        return (border1, filling, border2)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op