Hi, there. Here are two methods for this question, and the second one recursive function is actually the question wanted. But for the Test, there is no print outside the fuction name, so my question is how to print the sum of the result in the function, which means no matter what value we assign to the number we all can get the final result rather than rewrite a default main() and make num equal to sth, thks!
Write a recursive function named reverse_digits() that takes a positive integer as a parameter and prints the integer value reversely. This function has to be recursive; you are not allowed to use loops to solve this problem. Note You can assume that the parameter integer is a positive number. For example: Test Result reverse digits(1234) 4321 printO Answer: (penalty regime: 0 %) 1 def reverse_digits(number): 2 result0 while number0: result (result * 10) + number % 10 number number// 10 4 print(result) 10 def reverse_digitsCnumber): if number 10: return num 12 13v 14 15 else: return number % 10 * 10 ** (len(str(number)) – 1 ) + beverse_digitsCnumber // 10)