Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Recursive Function-Python 3 help What is wrong with my recursive function? only

ID: 3738674 • Letter: R

Question

Recursive Function-Python 3 help

What is wrong with my recursive function? only prints the print statement, does not execute

ones = ["", "one","two","three","four","five", "six", "seven","eight","nine"]

tens = ["ten","eleven","twelve","thirteen","fourteen", "fifteen", "sixteen",
"seventeen","eighteen", "nineteen"]

twenties = ["","","twenty","thirty","forty","fifty","sixty", "seventy", "eighty",
"ninety",]

thousands = ["","thousand","million","billion","trillion","quadrillion",
"sextillion", "septillion", "octillion", "nonillion","decillion",
"undecillion", "duodecillion","tredecillion","quattuordecillion",
"quindecillion", "sexdecillion", "septendecillion", "octodecillion",
"novemdecillion", "vigintillion"]

def int2words(n):
  
n3 = []
r1 = ""
  
ns = str(n)
for k in range(3, 33, 3):
r = ns[-k:]
q = len(ns) - k
  
if q < -2:
break
else:
if q >= 0:
n3.append(int(r[:3]))
elif q >= -1:
n3.append(int(r[:2]))
elif q >= -1:
n3.append(int(r[:1]))
r1 = r
  
nw = ""
  
for i, x in enumerate(n3):
b1 = x % 10
b2 = (x % 100)//10
b3 = (x % 1000)//100
  
if x == 0:
continue
else:
t = thousands[i]
if b2 == 0:
nw = ones[b1] + t + nw
elif b2 == 1:
nw = tens[b1] + t + nw
elif b2 > 1:
nw = twenties[b2] + ones[b1] + t + nw
  
if b3 > 0:
nw = ones[b3] + "hundred" + nw
return nw

if __name__ == '__main__':
  
n = 4321324567890
  
print("%d (in words) = %s")

Explanation / Answer

Because you didn't call that function what you implemented.So you need t call as

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote