Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

why this recursive function returns a tuple?

i wrote a simple recursive script to change decimal to hexadecimal, but it returns the answer in tuple, its not a big deal, i get what i want, but i would like to understand why i get a tuple, anyone could explain it?

this is the script:

def printDigits(n,base):
    if n < base:
        return n 
    else:
        return printDigits(n//base, base) , n % base

and for

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

print(printDigits(245, 16))

i get

(15, 5)

>Solution :

The return in the else statement of printDigits contains a comma, which is how you define a tuple in Python.

return printDigits(n//base, base) , n % base
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading