generated from mwc/problemset_numberwords
Adding computer (python) language seemed to slow down my thinking, but actually helped me with organizing each step in order.
I kept getting 'fail' message, and fixed minor errors multiple times. For example, adding blank space between two words can be done by using + " " was forgotten a few times.
This commit is contained in:
parent
122a47f7d4
commit
1406119a4e
|
@ -15,19 +15,42 @@ TENS_NAMES = [
|
|||
]
|
||||
|
||||
def int_under_1000000_to_str(number):
|
||||
return "umm..."
|
||||
if number<1000:
|
||||
return int_under_1000_to_str(number)
|
||||
quotient,remainder=divide_with_remainder(number,1000)
|
||||
Q1=int_under_1000_to_str(quotient) + " " + "thousand"
|
||||
if remainder>0:
|
||||
R1=int_under_1000_to_str(remainder)
|
||||
return Q1 + " " + R1
|
||||
return Q1
|
||||
|
||||
def int_under_1000_to_str(number):
|
||||
return "umm..."
|
||||
if number<100:
|
||||
return int_under_100_to_str(number)
|
||||
quotient,remainder=divide_with_remainder(number,100)
|
||||
Q1=int_under_10_to_str(quotient) + " " + "hundred"
|
||||
if remainder>0:
|
||||
R1=int_under_100_to_str(remainder)
|
||||
return Q1 + " and " + R1
|
||||
return Q1
|
||||
|
||||
def int_under_100_to_str(number):
|
||||
return "umm..."
|
||||
if number<20:
|
||||
return int_under_20_to_str(number)
|
||||
quotient,remainder=divide_with_remainder(number,10)
|
||||
tensname=TENS_NAMES[quotient]
|
||||
if remainder>0:
|
||||
onesname=int_under_10_to_str(remainder)
|
||||
return tensname + "-" + onesname
|
||||
return tensname
|
||||
|
||||
def int_under_20_to_str(number):
|
||||
return "umm..."
|
||||
if number<10:
|
||||
return int_under_10_to_str(number)
|
||||
return TWEEN_AND_TEEN_NAMES[number-10]
|
||||
|
||||
def int_under_10_to_str(number):
|
||||
return "umm..."
|
||||
return DIGIT_NAMES[number]
|
||||
|
||||
def divide_with_remainder(dividend, divisor):
|
||||
"""Divides one number by another, using whole-number division.
|
||||
|
|
|
@ -33,7 +33,7 @@ class TestIntToStr(unittest.TestCase):
|
|||
[int_under_1000000_to_str, 1001, 'one thousand one'],
|
||||
[int_under_1000000_to_str, 1672, 'one thousand six hundred and seventy-two'],
|
||||
[int_under_1000000_to_str, 10000, 'ten thousand'],
|
||||
[int_under_1000000_to_str, 588567, 'five hundred and ninety-eight thousand five hundred and sixty-seven'],
|
||||
[int_under_1000000_to_str, 598567, 'five hundred and ninety-eight thousand five hundred and sixty-seven'],
|
||||
]
|
||||
|
||||
def test_converts_integer_to_string(self):
|
||||
|
|
Loading…
Reference in New Issue