Question: This is a problem with python and functions. Problem 3 - decimal.py: Reverse digits [20 points] Write a function reverse that accepts a non negative

This is a problem with python and functions.
Problem 3 - decimal.py: Reverse digits [20 points] Write a function reverse that accepts a non negative integer argument n and returns the integer that has the reverse decimal representation. For example, the reverse of 12 is 2, and the reverse of both 21 and 210 is 12. Your function should also be placed in decimal.py As before, for full credit you should not use strings or lists Hint: For this problem, you wil need to iterate over the digits of an integer. One approach, which is often the first that comes to mind, is to convert to a string, then iterate over the characters of the string and convert each one baclk to an integer, e.g., something like for c in str (n) digitint (c) However, although this would work, it makes several conversions that are unnecessary. If you do not care about the order in which the digits are iterated over, then a better way uses simply integer division and remainder op- erations. This wl iterate over the digits from right to left. The idea is that you start with a number, let's call it remaining digits, which contains the yet un-visited digits. This would be initialized to n. You can ex- tract the last digit (ie., units position) simply by calculating remaining-digits % 10. Then you can replace remaining digits with remaining_digits // 10, which will effectively "chop off" the units digit. You iterate until remaining.digits becomes zero. In other words, your loop table for, say n-153 would be Init ter 1 Iter2 Iter 3 remaining-digits 15315 digit Hint: You wil also need to perform an "append digi" operation. For this, observe that if you have a number n and you append any digit d,0s d
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
