python - str() not returning string in my function -


so i've defined recursive function numtobaseb converts given number in base ten other base between 2 , 10. desired output string, reason keep getting int.

def numtobaseb(num, b):     if num == 0:         return ''     elif b > 10 or b < 2:         return "the base has between 2 , 10"     else:         return numtobaseb(num // b, b ) + str(num % b) 

so me: numtobaseb(4, 2) return

100

instead of desired output:

'100'

your program working designed:

>>> numtobaseb(1024,2) '10000000000' >>> numtobaseb(4,2) '100' 

of course, if print(numtobaseb(4,2)), quotes not displayed.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -