+ 1
Verbalize a Number with 27 numbers how do I start off the code?
2 ответов
+ 2
You can use a function to loop through the digits of a number like
def verbalize(number):
output = ''
for digit in number:
#do stuff with output here
return output
Then you can build the output digit by digit and take some rules into account:
last digit would be "one" to "nine" BUT if the one-to-last digit is 1 the last two digits combine as "ten" to "nineteen"
1-to-last digit is "twenty" to "ninety"
2-to-last digit is digit+"hundred"
3-to-last digit is digit+"thousand"
(you can use a dictionary for this: digit_to_verb{1:"one",2:"two"....} )
4-to-last is same as 1-to-last
5-to-last is same as 2-to-last
6-to-last is same as 3-to-last but with million
Up to billion, trillion et cetera
So for example 1234567 would be:
one million
two hundred
thirty
four
thousand
five hundred
sixty
seven
I wrote some code to illustrate this: https://code.sololearn.com/cf0GOZooA91c
0
thank you so is this the shortest steps to get to the income?