Answer must be solved Recursively neighbor(n, prev) Takes a positive integer n and a default argument prev and returns the number of digits in n that have the same digit to its left or to its right. Floor division (//) and modulo (%) operators are useful here. Forbidden methods, operators, and libraries: • You are not allowed to convert n to other data type such str() or list() • You are not allowed to use pow, the ** operator, or import any function (such as math.log) • You are not allowed to declare global variables • You are not allowed to use for/while loops in any form Preconditions n: int -> positive integer prev: int -> positive integer sequence of items Returns: int Examples: >>> neighbor(777) 3 >>> neighbor(469704) 0 >>> neighbor(411477) # 411477 4 >>> neighbor(7951452114587444436999) # 7951452114587444436999 9 >>> neighbor(22222222222222233) 17
Answer must be solved Recursively
neighbor(n, prev)
Takes a positive integer n and a default argument prev and returns the number of digits in n that
have the same digit to its left or to its right. Floor division (//) and modulo (%) operators are useful here.
Forbidden methods, operators, and libraries:
• You are not allowed to convert n to other data type such str() or list()
• You are not allowed to use pow, the ** operator, or import any function (such as math.log)
• You are not allowed to declare global variables
• You are not allowed to use for/while loops in any form
Preconditions
n: int -> positive integer
prev: int -> positive integer sequence of items
Returns: int
Examples:
>>> neighbor(777)
3
>>> neighbor(469704)
0
>>> neighbor(411477) # 411477
4
>>> neighbor(7951452114587444436999) # 7951452114587444436999
9
>>> neighbor(22222222222222233)
17

Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images









