problemset_numberwords/planning.md

1.8 KiB

Planning Number Words

Before you start programming, do some planning here on how you will break down this problem. Here's a hint: if you start by writing functions for smaller numbers, you will find that these functions help you with the larger numbers. For each of the cases below, explain how you would turn a number into a string. Feel free to write in sentences or in pseudocode (pseudocode is a sort of "casual programming" where you're almost writing in code, being pretty specific without worrying about syntax. For each case below, assume the integer is zero or more--don't worry about negative integers.

Integers under 10

(This one is done for you!) For an integer less than ten, you need to know the name of each digit, and look it up. You could use a big if/else statement like:

if number == 0:
    return "zero"
elif number == 1:
    return "one"
elif number == 1:
    return "two"

A cleaner way to do this would be to make a list of digit names, from zero to nine. Then you could just look up a digit's name:

digit_names = [
    "zero", "one", "two", "three", "four", 
    "five", "six", "seven", "eight", "nine"
]
return digit_names[number]

Integers under 20

If integer < 10, then return digit_names[number] Else return digit_names between 10 and 19

Integers under 100

If integer < 20, return "Integers under 20" Else return integer between 20 and 99 with proper "and"

Integers under 1000

If integer < 100, return "Integers under 100" Else return integer between 100 and 999 with proper "and"

Integers under 1000000

If integer < 1000, return "Integers under 1000" Else return integer between 1000 and 999999 with proper "and"

Negative integers down to -1 million

Use the above integers but add a negative symbol to all integers and reverse less than to greater than