"""Number to Russian words converter""" class NumberToWords: """Convert numbers to Russian words in nominative case""" def __init__(self): self.ones = ['', 'один', 'два', 'три', 'четыре', 'пять', 'шесть', 'семь', 'восемь', 'девять'] self.tens = ['', '', 'двадцать', 'тридцать', 'сорок', 'пятьдесят', 'шестьдесят', 'семьдесят', 'восемьдесят', 'девяносто'] self.teens = ['десять', 'одиннадцать', 'двенадцать', 'тринадцать', 'четырнадцать', 'пятнадцать', 'шестнадцать', 'семнадцать', 'восемнадцать', 'девятнадцать'] self.hundreds = ['', 'сто', 'двести', 'триста', 'четыреста', 'пятьсот', 'шестьсот', 'семьсот', 'восемьсот', 'девятьсот'] self.thousands = ['', 'одна', 'две', 'три', 'четыре', 'пять', 'шесть', 'семь', 'восемь', 'девять'] def _convert_hundreds(self, num: int) -> str: """Convert number 0-999 to words""" if num == 0: return '' result = [] # Hundreds hundred = num // 100 if hundred > 0: result.append(self.hundreds[hundred]) # Tens and ones remainder = num % 100 if 10 <= remainder <= 19: result.append(self.teens[remainder - 10]) else: ten = remainder // 10 one = remainder % 10 if ten > 0: result.append(self.tens[ten]) if one > 0: result.append(self.ones[one]) return ' '.join(result) def _convert_thousands(self, num: int) -> str: """Convert thousands part (0-999) to words with feminine forms""" if num == 0: return '' result = [] # Hundreds hundred = num // 100 if hundred > 0: result.append(self.hundreds[hundred]) # Tens and ones (with feminine forms for thousands) remainder = num % 100 if 10 <= remainder <= 19: result.append(self.teens[remainder - 10]) else: ten = remainder // 10 one = remainder % 10 if ten > 0: result.append(self.tens[ten]) if one > 0: result.append(self.thousands[one]) return ' '.join(result) def _thousand_word(self, num: int) -> str: """Get correct grammatical form of 'thousand' word""" if num % 100 in [11, 12, 13, 14]: return 'тысяч' last_digit = num % 10 if last_digit == 1: return 'тысяча' elif last_digit in [2, 3, 4]: return 'тысячи' else: return 'тысяч' def convert(self, num: int) -> str: """ Convert integer to Russian words in nominative case Args: num: Integer number to convert Returns: String representation of the number in Russian """ if num == 0: return 'ноль' if num < 0: return 'минус ' + self.convert(-num) result = [] # Millions millions = num // 1000000 if millions > 0: result.append(self._convert_hundreds(millions)) if millions % 100 in [11, 12, 13, 14]: result.append('миллионов') elif millions % 10 == 1: result.append('миллион') elif millions % 10 in [2, 3, 4]: result.append('миллиона') else: result.append('миллионов') # Thousands thousands = (num % 1000000) // 1000 if thousands > 0: result.append(self._convert_thousands(thousands)) result.append(self._thousand_word(thousands)) # Hundreds hundreds = num % 1000 if hundreds > 0: result.append(self._convert_hundreds(hundreds)) return ' '.join(result)