__ ___ ___ ___ ___ _____ ___ ___ ___ ___ _____ ___ ___ ___ ___ __
_| |_ |_| _| |_ |_| _| |_ _| |_ |_| _| |_ |_| _| |_ _| |_ |_| _| |_ |_| _| |_
| _ | _ |_ _| _ | _ | | _ | _ |_ _| _ | _ | | _ | _ |_ _| _ | _ |
|_| |_| | |___| |___| | |_| |_| |_| |_| | |___| |___| | |_| |_| |_| |_| | |___| |___| | |_| |_|
_ _ | ___ ___ | _ _ _ _ | ___ ___ | _ _ _ _ | ___ ___ | _ _
| |_| | |_| _| |_ |_| | |_| | | |_| | |_| _| |_ |_| | |_| | | |_| | |_| _| |_ |_| | |_| |
|_ _| _ |_ _| _ |_ _| |_ _| _ |_ _| _ |_ _| |_ _| _ |_ _| _ |_ _|
_| |___| |___| |___| |___| |_ _| |___| |___| |___| |___| |_ _| |___| |___| |___| |___| |_
| ___ ___ _ ___ ___ | | ___ ___ _ ___ ___ | | ___ ___ _ ___ ___ |
|_| _| |_ |_| |_| _| |_ |_| |_| _| |_ |_| |_| _| |_ |_| |_| _| |_ |_| |_| _| |_ |_|
_ |_ _| _ _ |_ _| _ _ |_ _| _ _ |_ _| _ _ |_ _| _ _ |_ _| _
| |___| |___| | | |___| |___| | | |___| |___| | | |___| |___| | | |___| |___| | | |___| |___| |
|_ _____ _| |_ _____ _| |_ _____ _| |_ _____ _| |_ _____ _| |_ _____ _|
_| |_ _| |_ _| |_ _| |_ _| |_ _| |_ _| |_ _| |_ _| |_ _| |_ _| |_ _| |_
| _ | | _ | | _ | | _ | | _ | | _ | | _ | | _ | | _ | | _ | | _ | | _ |
|_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_| |_|
This code currently only supports whole numbers up to 1 undecillian - maybe someday I'll solve it generally.
defsyllables(n):
defexp_syllables(exp):
ifexp>10:
raiseValueError("1 undecillion and above are not supported!")
# Assuming million, billion, and trillion are pronounced with two syllables,# while powers through decillion have three.returnexp<4and2or3ifn==0:
return0ifnin [1, 2, 3, 4, 5, 6, 8, 9, 10, 12]:
return1ifnin [11, 17, 70]:
return3ifn<=20ornin [30, 40, 50, 60, 80, 90]:
return2ifn<100:
returnsyllables(10* (n//10)) +syllables(n%10)
ifn<1000:
hundreds=n//100return (hundreds==7and4or3) +syllables(n-100*hundreds)
exp=int(math.log10(n) //3) # thousands, millions, billions, ...power=int(math.pow(1000, exp))
leftmost=n//powerremainder=n-leftmost*powerreturnsyllables(leftmost) +exp_syllables(exp) +syllables(remainder)






