Швец Игорь Станиславович 411 Казахстанский филиал CyberSausage 11088
Исанбеков Дамир 414 КФ CyberSausage 11229
f1from fractions import Fractionf1from fractions import Fraction
22
3class Sausage:3class Sausage:
44
n5    def __init__(self, stuffing='pork!', volume=1):n5    def __init__(self, ground='pork!', volume=1):
6        self.stuffing = stuffing6        self.ground = ground
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.stuffing, self.volume + other.volume)n13        return Sausage(self.ground, self.volume + other.volume)
1414
15    def __sub__(self, other):15    def __sub__(self, other):
n16        return Sausage(self.stuffing, max(self.volume - other.volume, 0)n16        return Sausage(self.ground, max(self.volume - other.volume, 0))
>) 
1717
18    def __mul__(self, factor):18    def __mul__(self, factor):
n19        return Sausage(self.stuffing, self.volume * factor)n19        return Sausage(self.ground, 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.stuffing, self.volume / divisor)n25        return Sausage(self.ground, 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        remainder = self.volume - full_loafsn34        remaining_fraction = self.volume - full_loafs
35        str1, str2, str3 = ('', '', '')35        top_border, ground_line, bottom_border = ('', '', '')
36        for _ in range(full_loafs):36        for _ in range(full_loafs):
n37            a, b, c = self._full_loaf()n37            a, b, c = self._create_full_loaf()
38            str1 += a38            top_border += a
39            str2 += b39            ground_line += b
40            str3 += c40            bottom_border += c
41        if remainder > 0:41        if remaining_fraction > 0:
42            a, b, c = self._partial_loaf(remainder)42            a, b, c = self._create_partial_loaf(remaining_fraction)
43            str1 += a43            top_border += a
44            str2 += b44            ground_line += b
45            str3 += c45            bottom_border += c
46        return str1 + '\n' + (str2 + '\n') * 3 + str346        return top_border + '\n' + (ground_line + '\n') * 3 + bottom_bor
 >der
4747
n48    def _full_loaf(self):n48    def _create_full_loaf(self):
49        remain = 12 % len(self.stuffing)49        ground_remainder = 12 % len(self.ground)
50        main = 12 // len(self.stuffing)50        ground_main = 12 // len(self.ground)
51        border1 = '/------------\\'51        top_border = '/------------\\'
52        filling = f'|{self.stuffing * main + self.stuffing[:remain]}|'52        ground_line = f'|{self.ground * ground_main + self.ground[:groun
 >d_remainder]}|'
53        border2 = '\\------------/'53        bottom_border = '\\------------/'
54        return (border1, filling, border2)54        return (top_border, ground_line, bottom_border)
5555
t56    def _partial_loaf(self, fraction):t56    def _create_partial_loaf(self, fraction):
57        len_of_remain = fraction.numerator * (12 // fraction.denominator57        total_ground_length = fraction.numerator * (12 // fraction.denom
>)>inator)
58        count_of_word = len_of_remain // len(self.stuffing)58        ground_count = total_ground_length // len(self.ground)
59        len_of_rest_word = len_of_remain - count_of_word * len(self.stuf59        leftover_ground_length = total_ground_length - ground_count * le
>fing)>n(self.ground)
60        border1 = '/' + '-' * len_of_remain + '|'60        top_border = '/' + '-' * total_ground_length + '|'
61        filling = f'|{self.stuffing * count_of_word + self.stuffing[:len61        ground_line = f'|{self.ground * ground_count + self.ground[:left
>_of_rest_word]}|'>over_ground_length]}|'
62        border2 = '\\' + '-' * len_of_remain + '|'62        bottom_border = '\\' + '-' * total_ground_length + '|'
63        return (border1, filling, border2)63        return (top_border, ground_line, bottom_border)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op