Question #80039

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

Expert's answer

def intreverse(n):
res=0
while(n > 0):
lastDig = n %10
res = res *10 + lastDig
n = n //10
return res
LATEST TUTORIALS
APPROVED BY CLIENTS