Answer to Question #80492 in Python for revanth

Question #80492
Write a function intreverse(n) that takes as input a positive integer n and returns the integer obtained by reversing the digits in n.

Here are some examples of how your function should work.

>>> intreverse(783)
387
>>> intreverse(242789)
987242
>>> intreverse(3)
3
1
Expert's answer
2018-09-07T05:11:36-0400
Answer
def intreverse(number, res=0):
if number==0:
return res
else : res=(res*10)+number%10
return intreverse (number//10,res)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS