Janet Wang - 2 years ago 56
Python Question

# Python: Why doesn't my program print anything?

If I use print() only, it'll print the spelling of the number in the range of 0-1000, but I'd like to save the result as a variable with return() to assign it to other functions later. When I test it, it does not print any thing out with return(), where is the problem? Thanks!

update: it turned out I called return() before print(), so print() would never get called; but then I switched their position, it still doesn't work, why? Thanks.

``````number = int (input ("Please enter a number between -999,999,999 to 999,999,999: "))
listA= ('zero','one','two', 'three','four','five','six','seven','eight','nine','ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen')
listB= ('','','twenty','thirty','forty','fifty','sixty','seventy','eighty','ninety')
listC= ('','one','two', 'three','four','five','six','seven','eight','nine','ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen')
# print the spelling of integers between -999,999,999 to 999,999,999
def spell(Numbers):
result = []
# print the splling of integers between 0 to 999
def spellOne(Numbers):
if 0 <= Numbers < 1000:
Number3 = Numbers // 100
Number2 = Numbers // 10 % 10
Number1 = Numbers % 10
F = Numbers % 100

if Number3 != 0:
if Number2 != 0:
if F < 20:
result.append(listA[Number3] + " hundred " + listA[F])

elif 20 <= F < 100:
if Number1 != 0:
result.append(listA[Number3] + " hundred " + listB[Number2] + "-" +listC[Number1])
else:
result.append(listA[Number3] + " hundred " + listB[Number2])
else:
Number1 != 0
result.append(listA[Number3] + " hundred " + listC[Number1])
else:
if F < 20:
result.append(listA[F])

elif 20 <= F < 100:
if Number1 != 0:
result.append(listB[Number2] + "-" + listC[Number1])

else:
result.append(listB[Number2])

print (result)
return(result)

spellOne(number)
``````

I believe that you need to call `spellOne(number)` before you print or even return the results so that the second function works. Because when you call `spell` all it will do is print `result` which is an empty list. Then it will return it and not even get to the next line. With the way it was before the second function will never get called unless you put it before.
``````spellOne(number)