Reversing the output of a function in python that is not a list

64 views Asked by At

I will get a number for the output of this piece of code:

base = int(raw_input("Pick your base:  "))
base = str(base)
question = "Pick your number! (the base is "+base+" ):  "
number = int(raw_input(question))
def func(number):
    if number != 0: 
        sec = number/int(base)
        third = number - (sec * int(base)) 
        print third,
        func(sec) 
func(number)

I want to take the output (for example 2435) and reverse it (to 5342). I have tried the a[::-1] by assigning the func(number) to a variable and then printing that variable[::-1] however this does not seem to work:

x = func(number)   
print x[::-1]

That gives me:

TypeError: 'NoneType' object has no attribute 'getitem'

1

There are 1 answers

0
Falko On BEST ANSWER

Your method func is missing a return statement (and thus returns None). Without returning a value, you can't apply the index operator on it.