0

the point of my recursion function is to print integers in reverse order. def rDisp(s): n=str(s) if n == "": return n else: return rDisp(n[1:]) + n[0]

def main():
    number=(int(input("Enter a number :")))
    rDisp(num)

main()

If within the main function I implement print(reverseDisplay(number)), it works, however, for the purpose of this code, I want the reverseDisplay function to do the printing. How would I go about implementing the print function into that block of code.

Thanks!

3
  • You use the print() function. I really don't know what you are asking. Commented Nov 7, 2012 at 6:28
  • Within the function, reverseDisplay(s), where do I implement the print function. Attempting to return print(reversedDisplay(n[1:])+n[0]) has not worked, and instead returns an error. Commented Nov 7, 2012 at 6:35
  • You don't return print(), you print(). Commented Nov 7, 2012 at 7:02

2 Answers 2

1

Untested code:

def reversePrint(s):
    if not s: 
        return
    print(s[-1])
    reversePrint(s[:-1])

def main():
    number=input("Enter a number :")
    reversePrint(number)

main()
Sign up to request clarification or add additional context in comments.

1 Comment

Yeah thanks! That's basically it but I just messed around with it until I got all of the output on the same line
0

Just got it

def reverseDisplay(s):
    n=str(s)
    if n == "":
        return n
    else:
        reverseDisplay(n[1:])
        b=n[0]
        print(b,end='')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.