# Recursive Function Numbers to English

Page 1 of 1

## 1 Replies - 786 Views - Last Post: 08 December 2011 - 11:26 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=258812&amp;s=29b61ea5584ac8b4afa9163b28542136&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 benmiesner

Reputation: 0
• Posts: 11
• Joined: 18-November 11

# Recursive Function Numbers to English

Posted 06 December 2011 - 07:04 PM

Write a recursive function to print the digits of a number in English. For example, the number 153's output should be "One Five Three"
b. Obtain numbers from the user and display the English digits for each number entered. You may terminate the loop based on a sentinel value or by first asking the user how many numbers will
be entered.
```def getNumbers():
n = []
xStr = input("Enter first digit of number (negative to quit) >> ")
integer = int(xStr)
while  integer >= 0:
while xStr != "":
x = eval(xStr)
n.append(x)
xStr = input("Enter next digit of number (negative to quit) >> ")
return n

def displayEnglishDigits(number):
number = getNumbers()
if len(number) == 0:
return None
if len(number) == 1:
return number[0]
else:
value = displayEnglishDigits(number[1:])
return value

def display(values):
print(displayEnglishDigits(number))

def main():
numb = getNumbers()
nums = displayEnglishDigits(numb)
display(nums)

main()

```

Is This A Good Question/Topic? 0

## Replies To: Recursive Function Numbers to English

### #2 cupidvogel

Reputation: 31
• Posts: 593
• Joined: 25-November 10

## Re: Recursive Function Numbers to English

Posted 08 December 2011 - 11:26 PM

Strange, I saw a near similar question by some other user in this section, with the same problem in his code! Firstly there is no recursion here. Recursive function is a function that continuously calls itself with a set of parameters revised during its current iteration. There is no such function here. You are using loop to accept a number??? Why, just assign the input number to a variable, check for abnormalities (whether it contains an a non-digit), and then extract its digits using a recursive function (or just a plain while/for loop), match them against a list containing one, two, three,...nine etc and print them out!