ChatCrawlerпоиск по публичному Telegram Открыть приложение
О

Основы Python

сообщение · 2025-09-28 12:31 UTC
A
Ответсообщение недоступно
всем добрый день. помогите, пожалуйста — валится на 15-ом тесте из-за RE self.a у меня числитель, self.b — знаменатель from functools import total_ordering @total_ordering class Fraction(): def __init__(self, *args): self.b = 1 if isinstance(args[0], str): if len(args[0]) == 1: self.a = int(args[0]) else: self.a, self.b = map(int, args[0].split('/')) elif len(args) == 1 and isinstance(args[0], int): self.a = args[0] else: self.a = args[0] self.b = args[1] self.__reduction() def numerator(self, number=None): if number is None: return abs(self.a) else: self.a = number * self.__sign() self.__reduction() def denominator(self, number=None): if number is None: return abs(self.b) else: self.b = number * self.__sign() self.__reduction() def __str__(self): return f'{self.a}/{self.b}' def __repr__(self): return f"Fraction('{self.a}/{self.b}')" def __neg__(self): return Fraction(-self.a, self.b) def _check_other(self, other): if isinstance(other, int): return Fraction(other, 1) return other def __add__(self, other): other = self._check_other(other) den = self.b * other.b num = self.a * other.b + other.a * self.b return Fraction(num, den) def __sub__(self, other): return self + (- other) def __iadd__(self, other): other = self._check_other(other) den = self.b * other.b self.a = self.a * other.b + other.a * self.b self.b = den self.__reduction() return self def __isub__(self, other): return self.__iadd__(- other) def __reduction(self): div = self.__gcd(self.a, self.b) self.a //= div self.b //= div if self.b < 0: self.a, self.b = -self.a, abs(self.b) return self.a, self.b def __sign(self): return - 1 if self.a < 0 else 1 def __gcd(self, first, second): while second: first, second = second, first % second return abs(first) def __mul__(self, other): num = self.a * other.a den = self.b * other.b return Fraction(num, den) def __imul__(self, other): self.a *= other.a self.b *= other.b self.__reduction() return self def __truediv__(self, other): return self * other.reverse() def __itruediv__(self, other): return self.__imul__(other.reverse()) def reverse(self): return Fraction(self.b, self.a) def __lt__(self, other): other = self._check_other(other) return self.a * other.b < other.a * self.b def __eq__(self, other): other = self._check_other(other) return True if self.a == other.a and self.b == other.b else False

Вся лента · оригинал в Telegram

Открыть в Telegram Каталог площадок Искать в ChatCrawler

Слепок открытой публичной ленты из поискового индекса ChatCrawler — «Google по публичному Telegram»; обновляется по мере обхода площадки. Время — UTC.

Только публичный контент, официальный API Telegram. О проекте · Вопросы · Чего мы не делаем · Убрать страницу из выдачи · Каталог