Created
April 21, 2025 18:04
-
-
Save dipendra-sharma/5d315e5fdbcb317a17a18bdb6d4f46f8 to your computer and use it in GitHub Desktop.
A Python function/script that takes a numerical input and returns its representation in Hindi words (Devanagari script), following the Indian place value system (e.g., लाख, करोड़).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Complete mapping for 0-99 in Hindi | |
hindi_numbers_0_99 = [ | |
'शून्य', 'एक', 'दो', 'तीन', 'चार', 'पाँच', 'छह', 'सात', 'आठ', 'नौ', | |
'दस', 'ग्यारह', 'बारह', 'तेरह', 'चौदह', 'पंद्रह', 'सोलह', 'सत्रह', 'अठारह', 'उन्नीस', | |
'बीस', 'इक्कीस', 'बाईस', 'तेईस', 'चौबीस', 'पच्चीस', 'छब्बीस', 'सत्ताईस', 'अट्ठाईस', 'उनतीस', | |
'तीस', 'इकतीस', 'बत्तीस', 'तैंतीस', 'चौंतीस', 'पैंतीस', 'छत्तीस', 'सैंतीस', 'अड़तीस', 'उनतालीस', | |
'चालीस', 'इकतालीस', 'बयालीस', 'तैंतालीस', 'चवालीस', 'पैंतालीस', 'छियालीस', 'सैंतालीस', 'अड़तालीस', 'उनचास', | |
'पचास', 'इक्यावन', 'बावन', 'तिरेपन', 'चौवन', 'पचपन', 'छप्पन', 'सत्तावन', 'अट्ठावन', 'उनसठ', | |
'साठ', 'इकसठ', 'बासठ', 'तिरसठ', 'चौंसठ', 'पैंसठ', 'छियासठ', 'सड़सठ', 'अड़सठ', 'उनहत्तर', | |
'सत्तर', 'इकहत्तर', 'बहत्तर', 'तिहत्तर', 'चौहत्तर', 'पचहत्तर', 'छिहत्तर', 'सत्तहत्तर', 'अठहत्तर', 'उन्यासी', | |
'अस्सी', 'इक्यासी', 'बयासी', 'तिरासी', 'चौरासी', 'पचासी', 'छियासी', 'सत्तासी', 'अठासी', 'नवासी', | |
'नब्बे', 'इक्यानवे', 'बानवे', 'तिरानवे', 'चौरानवे', 'पचानवे', 'छियानवे', 'सत्तानवे', 'अट्ठानवे', 'निन्यानवे' | |
] | |
# Covers all major Indian units up to mahasinghmahasinghant (10^55) | |
def num_to_indian_words_hindi(num): | |
units = [ | |
(10**55, 'महासिंहमहासिंहांत'), | |
(10**53, 'सिंहमहासिंहांत'), | |
(10**51, 'शिष्टमहासिंहांत'), | |
(10**49, 'परार्धमहासिंहांत'), | |
(10**47, 'मध्यमहासिंहांत'), | |
(10**45, 'आदिमहासिंहांत'), | |
(10**43, 'महासिंहांत'), | |
(10**41, 'सिंहांत'), | |
(10**39, 'शिष्टांत'), | |
(10**37, 'परार्धांत'), | |
(10**35, 'मध्यांत'), | |
(10**33, 'आदांत'), | |
(10**31, 'महासिंघर'), | |
(10**29, 'सिंघर'), | |
(10**27, 'शिष्ट'), | |
(10**25, 'परार्ध'), | |
(10**23, 'मध्य'), | |
(10**21, 'अंत्य'), | |
(10**19, 'महाशंख'), | |
(10**17, 'शंख'), | |
(10**15, 'पद्म'), | |
(10**13, 'नील'), | |
(10**11, 'खरब'), | |
(10**9, 'अरब'), | |
(10**7, 'करोड़'), | |
(10**5, 'लाख'), | |
(10**3, 'हज़ार'), | |
(10**2, 'सौ') | |
] | |
if num == 0: | |
return hindi_numbers_0_99[0] | |
words = [] | |
n = num | |
for value, name in units: | |
q, n = divmod(n, value) | |
if q: | |
if q < 100: | |
words.append(hindi_numbers_0_99[q] + ' ' + name) | |
else: | |
words.append(num_to_indian_words_hindi(q) + ' ' + name) | |
if n: | |
if n < 100: | |
words.append(hindi_numbers_0_99[n]) | |
else: | |
words.append(num_to_indian_words_hindi(n)) | |
return ' '.join(words).strip() | |
# Main function to test num_to_words | |
def main(): | |
# Test with a very large number | |
n = 9876543210 | |
print(num_to_indian_words_hindi(n)) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment