File size: 6,372 Bytes
5d0af5f c3be3fb 5d0af5f c3be3fb 5d0af5f c3be3fb 5d0af5f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
def amharic_number_reader(number):
nums = []
val = list(number) # Convert the number string to a list of digits
readNums1 = ["አንድ", "ሁለት", "ሶስት", "አራት", "አምስት", "ስድስት", "ሰባት", "ስምንት", "ዘጠኝ", "ዜሮ"]
readNums2 = ["አስራ", "ሃያ", "ሰላሳ", "አርባ", "ሃምሳ", "ስልሳ", "ሰባ", "ሰማንያ", "ዘጠና"]
readNums3 = ["", "መቶ", "ሺ", "አስር ሺ", "መቶ ሺ", "ሚልዮን", "አስር ሚልዮን", "ቢልዮን", "አስር ቢልዮን", "ትሪልዮን"]
group_count = len(val)
for i, digit in enumerate(val):
digit = int(digit)
position = group_count - i - 1 # Position from the right
if position == 12: # Trillions
if digit != 0:
nums.append(readNums1[digit - 1])
nums.append(readNums3[9]) # 'ትሪልዮን'
elif position == 11: # Hundreds of trillions
if digit != 0:
nums.append(readNums1[digit - 1])
nums.append(readNums3[1]) # 'መቶ'
elif position == 10: # Tens of trillions
if digit != 0:
nums.append(readNums2[digit - 1])
elif position == 9: # Billions
if digit != 0:
nums.append(readNums1[digit - 1])
nums.append(readNums3[7]) # 'ቢልዮን'
elif position == 8: # Hundreds of billions
if digit != 0:
nums.append(readNums1[digit - 1])
nums.append(readNums3[1]) # 'መቶ'
elif position == 7: # Tens of billions
if digit != 0:
nums.append(readNums2[digit - 1])
elif position == 6: # Millions
if digit != 0:
nums.append(readNums1[digit - 1])
nums.append(readNums3[5]) # 'ሚልዮን'
elif position == 5: # Hundreds of thousands
if digit != 0:
nums.append(readNums1[digit - 1])
nums.append(readNums3[1]) # 'መቶ'
elif position == 4: # Tens of thousands
if digit != 0:
nums.append(readNums2[digit - 1])
elif position == 3: # Thousands
if digit != 0:
nums.append(readNums1[digit - 1])
nums.append(readNums3[2]) # 'ሺ'
elif position == 2: # Hundreds
if digit != 0:
nums.append(readNums1[digit - 1])
nums.append(readNums3[1]) # 'መቶ'
elif position == 1: # Tens
if digit != 0:
nums.append(readNums2[digit - 1])
elif position == 0: # Ones
if digit != 0:
nums.append(readNums1[digit - 1])
return " ".join(nums) # Return as a sentence
def tigrigna_number_reader(number):
nums = []
val = list(number) # Convert the number string to a list of digits
readNums1 = ["ሓደ", "ክልተ", "ሰለስተ", "ኣርባዕተ", "ሓሙሽተ", "ሽዱሽተ", "ሸዋዓተ", "ሸሞንተ", "ትሽዓተ", "ባዶ"]
readNums2 = ["ዓሰርተ", "ዕስራ", "ሰላሳ", "ዓርባዓ", "ሓምሳ", "ስልሳ", "ሰብዓ", "ሰማንያ", "ቴስዓ"]
readNums3 = ["", "ምእቲ", "ሽሕ", "ዓስርተ ሽሕ", "መቶ ሺሕ", "ሚልዮን", "ዓስርተ ሚልዮን", "ቢልዮን", "ዓስርተ ቢልዮን", "ትሪልዮን"]
group_count = len(val)
for i, digit in enumerate(val):
digit = int(digit)
position = group_count - i - 1 # Position from the right
if position == 12: # Trillions
if digit != 0:
nums.append(readNums1[digit - 1])
nums.append(readNums3[9]) # 'ትሪልዮን'
elif position == 11: # Hundreds of trillions
if digit != 0:
nums.append(readNums1[digit - 1])
nums.append(readNums3[1]) # 'መቶ'
elif position == 10: # Tens of trillions
if digit != 0:
nums.append(readNums2[digit - 1])
elif position == 9: # Billions
if digit != 0:
nums.append(readNums1[digit - 1])
nums.append(readNums3[7]) # 'ቢልዮን'
elif position == 8: # Hundreds of billions
if digit != 0:
nums.append(readNums1[digit - 1])
nums.append(readNums3[1]) # 'መቶ'
elif position == 7: # Tens of billions
if digit != 0:
nums.append(readNums2[digit - 1])
elif position == 6: # Millions
if digit != 0:
nums.append(readNums1[digit - 1])
nums.append(readNums3[5]) # 'ሚልዮን'
elif position == 5: # Hundreds of thousands
if digit != 0:
nums.append(readNums1[digit - 1])
nums.append(readNums3[1]) # 'መቶ'
elif position == 4: # Tens of thousands
if digit != 0:
nums.append(readNums2[digit - 1])
elif position == 3: # Thousands
if digit != 0:
nums.append(readNums1[digit - 1])
nums.append(readNums3[2]) # 'ሺ'
elif position == 2: # Hundreds
if digit != 0:
nums.append(readNums1[digit - 1])
nums.append(readNums3[1]) # 'መቶ'
elif position == 1: # Tens
if digit != 0:
nums.append(readNums2[digit - 1])
elif position == 0: # Ones
if digit != 0:
nums.append(readNums1[digit - 1])
return " ".join(nums) # Return as a sentence
# Example Outputs
print(amharic_number_reader("1221"))
#ሓደ ሽሕን ክልተ ምእቲን ዕስራን ሓደን
print(amharic_number_reader("221222345681"))
#ክልተ ምእቲ ዕስራ ሓደ ቢልዮንን ክልተ ምእቲ ዕስራ ክልተ ሚልዮንን ሰለስተ ምእቲ ዓርባዓ ሓሙሽተ ሽሕን ሽዱሽተ ምእቲን ሰማንያን ሓደን
print(amharic_number_reader("8221222345681"))
#ሸሞንተ ትሪልዮን ክልተ ምእቲ ዕስራ ሓደ ቢልዮን ክልተ ምእቲ ዕስራ ክልተ ሚልዮን ሰለስተ ምእቲ ዓርባዓ ሓሙሽተ ሽሕ ሽዱሽተ ምእቲ ሰማንያ ሓደ
|