233k views
0 votes
Write a function reverse() that accepts a nonnegative integer argument n and returns the integer that has the reverse decimal representation. For example, the reverse of 12 is 21, and the reverse of both 21 and 210 is 12. Your function should also be placed in decimal.py

1 Answer

3 votes

Answer:

the code is attached.

Step-by-step explanation:

  1. First check the parameter and if it is negative, print "please enter a nonnegative integer"
  2. then using str(), convert the parameter into string
  3. using slice operation [::-1] reverse the string
  4. return it as an integer using int()
Write a function reverse() that accepts a nonnegative integer argument n and returns-example-1
User Ben Jarman
by
5.7k points