A forum for general discussion of the Python programming language.


Postby mo711 » Thu Sep 19, 2013 1:44 pm

Hello! i need help, what i need to do is Extract digits using a base, basically i need to write a recursive function dec2base(n, b) that returns the list of base b digits in the positive integer n and the output has to be in this format:

dec2base(120, 10) => [1,2,0] (1*10**2 + 2*10**1 + 0*10**0)

basically, this is what ive written:

Code: Select all
def dec2base(n,b):
    add = n%b
    if n <= 1:
        return str(n)
        return str(convert(n//b,b)) + str(add)

but i am stuck and dont know what to do. any help???
Last edited by stranac on Thu Sep 19, 2013 1:49 pm, edited 1 time in total.
Reason: Added code tags, locked post
Posts: 1
Joined: Thu Sep 19, 2013 1:37 pm


Postby stranac » Thu Sep 19, 2013 1:52 pm

Your function is not called convert, it's dec2base...
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
Posts: 1143
Joined: Thu Feb 07, 2013 3:42 pm

Return to General Discussions

Who is online

Users browsing this forum: Crimson King, Google Feedfetcher, Google [Bot], micseydel and 2 guests