def translateSmallNumber(num): this = globals()[sys._getframe().f_code.co_name] maxLimit = Lakh translation = "" integerAssert(num, this) if num < 0: if num > -maxLimit: translation = minusSignWord + " " + translateSmallNumber(-num) elif num in basicNumbers.keys(): translation = basicNumbers[num] elif num < 100: t10 = tens[num / 10] t1 = basicNumbers[num % 10] translation = t10 + " " + t1 if t1 == basicNumbers[0]: translation = t10 elif num < 1000: t100 = basicNumbers[num / 100] + " " + biggerNumbers[100] rest = translateSmallNumber(num % 100) translation = t100 + andConjunction + rest if rest == basicNumbers[0]: translation = t100 elif num < Lakh: t1000 = translateSmallNumber(num / 1000) + " " + biggerNumbers[1000] rest = translateSmallNumber(num % 1000) translation = t1000 + " " + rest if rest == basicNumbers[0]: translation = t1000 elif (num % 1000) < 100: translation = t1000 + andConjunction + rest return translation
def translateNumber(num): this = globals()[sys._getframe().f_code.co_name] integerAssert(num, this) if num > -Lakh and num < Lakh: return translateSmallNumber(num) else: system = raw_input( "In which system do you want the number? Indian (H) or international (I)? " ).lower() if system == 'h': return translateNumIndian(num) elif system == 'i': return translateNumInternational(num) else: print "Invalid input for number system.\n" return "error"
def translateNumIndian(num): this = globals()[sys._getframe().f_code.co_name] translation = "" integerAssert(num, this) if num > -Lakh and num < Lakh: return translateSmallNumber(num) elif num < 0: translation = minusSignWord + " " + translateNumIndian(-num) elif num < Crore: tLakh = translateSmallNumber(num / Lakh) + " " + biggerNumbers[Lakh] rest = translateSmallNumber(num % Lakh) translation = tLakh + " " + rest if rest == basicNumbers[0]: translation = tLakh if (num / Lakh) > 1: translation += pluralMarker elif (num % Lakh) < 100: translation = tLakh + andConjunction + rest else: tCrore = translateNumIndian(num / Crore) + " " + biggerNumbers[Crore] rest = translateNumIndian(num % Crore) translation = tCrore + " " + rest if rest == basicNumbers[0]: translation = tCrore if (num / Crore) > 1: translation += pluralMarker elif (num % Crore) < 100: translation = tCrore + andConjunction + rest return translation
def translateNumber(num): this = globals()[sys._getframe().f_code.co_name] integerAssert(num, this) maxLimit = 1000 translation = "" if num < 0: if num > -maxLimit: translation = minusSignWord + " " + translateNumber(-num) elif num in basicNumbers.keys(): translation = basicNumbers[num] elif num >= 11 and num < 20: t10 = elevenToTwentyPrefixes(num % 10) t1 = basicNumbers[num % 10] translation = t10 + t1 elif num < 100: t10 = decade[num / 10] t1 = basicNumbers[num % 10] translation = makePrefix(num, t10) + " " + t1 if t1 == basicNumbers[0]: translation = t10 elif num < 800: n100 = num / 100 t100 = "" rest = translateNumber(num % 100) if n100 == 1: t100 = biggerNumbers[100] else: t100 = hundredPrefixes[n100] + biggerNumbers[100] translation = makePrefix(num, t100) + " " + rest if rest == basicNumbers[0]: translation = t100 elif num < 1000: t100 = biggerNumbers[100 * (num / 100)] rest = translateNumber(num % 100) translation = makePrefix(num, t100) + " " + rest if rest == basicNumbers[0]: translation = t100 elif num < Lakh: n1000 = num / 1000 t1000 = "" rest = translateNumber(num % 1000) if n1000 == 1: t1000 = biggerNumbers[1000] else: t1000 = translateNumber(n1000)[:-1] + biggerNumbers[1000] translation = makePrefix(num, t1000) + " " + rest if rest == basicNumbers[0]: translation = t1000 return translation
def translateNumber(num): this = globals()[sys._getframe().f_code.co_name] integerAssert(num, this) translation = "" if num < 0: translation = minusSignWord + " " + translateNumber(-num) elif num in basicNumbers.keys(): translation = basicNumbers[num] elif num >= 11 and num < 20: t10 = basicNumbers[10] t1 = translateNumber(num % 10) translation = t10 + " " + t1 elif num < 100: t10 = translateNumber(num / 10) + " " + basicNumbers[10] t1 = translateNumber(num % 10) translation = t10 + " " + t1 if t1 == basicNumbers[0]: translation = t10 elif num < 1000: t100 = translateNumber(num / 100) + " " + biggerNumbers[100] if (num / 100) == 2: t100 = synonyms[2] + " " + biggerNumbers[100] rest = translateNumber(num % 100) translation = t100 + " " + rest if rest == basicNumbers[0]: translation = t100 elif secondDigit(num) == 0: translation = t100 + zeroConjunction + rest elif num < Wan: t1000 = translateNumber(num / 1000) + " " + biggerNumbers[1000] rest = translateNumber(num % 1000) translation = t1000 + " " + rest if rest == basicNumbers[0]: translation = t1000 elif secondDigit(num) == 0: translation = t1000 + zeroConjunction + rest elif num < Yi4: tWan = translateNumber(num / Wan) + " " + biggerNumbers[Wan] rest = translateNumber(num % Wan) translation = tWan + " " + rest if rest == basicNumbers[0]: translation = tWan elif secondDigit(num) == 0: translation = tWan + zeroConjunction + rest else: tYi4 = translateNumber(num / Yi4) + " " + biggerNumbers[Yi4] rest = translateNumber(num % Yi4) translation = tYi4 + " " + rest if rest == basicNumbers[0]: translation = tYi4 elif secondDigit(num) == 0: translation = tYi4 + zeroConjunction + rest return translation