Add n then reverse digits sequence (1.5 points)¶
Given a positive integer n, a sequence is defined as follows. The
first term is 0. Any other term is computed by adding n to the
previous term and then reversing the digits. Note that this
sequence is not increasing.
Write function add_reverse() that takes two positive
integers, n and nmax (int), and computes the
terms of the previous sequence until it finds the first term that is
greater than nmax, which must not be included in the sequence. This
function returns a list in which all these terms are
stored in the order in which they are generated. Examples:
>>> add_reverse(2, 200) [0, 2, 4, 6, 8, 1, 3, 5, 7, 9, 11, 31, 33, 53, 55, 75, 77, 97, 99, 101] >>> add_reverse(2, 7) [0, 2, 4, 6] >>> add_reverse(4, 200) [0, 4, 8, 21, 52, 65, 96, 1, 5, 9, 31, 53, 75, 97, 101] >>> add_reverse(4, 50) [0, 4, 8, 21]Note
You have more tests in file
test-add_reverse.txt