generated from mwc/problemset_numberwords
Checkpoint 1: I finished planning.md
This commit is contained in:
parent
6db0e16e45
commit
3edf63eaf0
43
planning.md
43
planning.md
|
@ -38,18 +38,57 @@ return digit_names[number]
|
||||||
If the integer is under 10, then use the procedure described above.
|
If the integer is under 10, then use the procedure described above.
|
||||||
Otherwise, ... (this is where you take over!)
|
Otherwise, ... (this is where you take over!)
|
||||||
|
|
||||||
## Integers under 100
|
We can again make a list of digit names:
|
||||||
|
|
||||||
|
```
|
||||||
|
digit_names = [
|
||||||
|
"zero", "one", "two", "three", "four",
|
||||||
|
"five", "six", "seven", "eight", "nine",
|
||||||
|
"ten", "eleven", "twelve", "thirteen",
|
||||||
|
"fourteen", "fifteen", "sixteen",
|
||||||
|
"seventeen", "eighteen", "nineteen"
|
||||||
|
]
|
||||||
|
return digit_names[number]
|
||||||
|
```
|
||||||
|
|
||||||
|
## Integers under 100
|
||||||
|
If the integer is under 20, then use the procedure described above.
|
||||||
|
Otherwise,
|
||||||
|
|
||||||
|
First, create a list of tens digit strings:
|
||||||
|
```
|
||||||
|
tens_names = [
|
||||||
|
"twenty", "thirty", "forty", "fifty",
|
||||||
|
"sixty", "seventy", "eighty", "ninety"
|
||||||
|
]
|
||||||
|
```
|
||||||
|
Second, determine the leading digit, using integer division by 10, and the ones digit using mod 10 and look up the correct names.
|
||||||
|
return tens_names[number / 10 - 2] + digit_names[number % 10]
|
||||||
|
|
||||||
## Integers under 1000
|
## Integers under 1000
|
||||||
|
If the integer is under 100, then use the procedure described above. We'll call that procedure tens_number().
|
||||||
|
Otherwise,
|
||||||
|
|
||||||
|
First, create a list of hundreds digit srings:
|
||||||
|
```
|
||||||
|
hundreds_names = [
|
||||||
|
"one hundred", "two hundred", "three hundred",
|
||||||
|
"four hundred", "five hundred", "six hundred",
|
||||||
|
"seven hundred", "eight hundred", "nine hundred"
|
||||||
|
]
|
||||||
|
```
|
||||||
|
Second determine the hundreds digit using integer division by one hundred, the tens digit by finding the number mod 100 and applying tens_number(), and the ones digit by finding the number mod 10.
|
||||||
|
return hundreds_name[number / 100] + tens_number(number % 100) + digit_names[number % 10]
|
||||||
|
|
||||||
## Integers under 1000000
|
## Integers under 1000000
|
||||||
|
If the integer is under 1000, then use the procedure described above. We'll call that procedure hundreds_name().
|
||||||
|
|
||||||
|
return hundreds_name(number / 1000) + "thousand" + hundreds_name(number % 1000)
|
||||||
|
|
||||||
## Negative integers down to -1 million
|
## Negative integers down to -1 million
|
||||||
We won't deal with negative integers in this problem set,
|
We won't deal with negative integers in this problem set,
|
||||||
but how would you deal with a negative integer, using the
|
but how would you deal with a negative integer, using the
|
||||||
functions above?
|
functions above?
|
||||||
|
|
||||||
|
If the number is positive, use the above method.
|
||||||
|
Otherwise, return "negative " + number_words(-1 * number)
|
Loading…
Reference in New Issue