Good day. The task is to write a function that takes an input string with an integer. If the number is even, divide by 2. If odd, multiply by 3 and add 1. Do the same results, depending on the parity, of course. The output should be a string with a sequence of all result numbers separated by a space. The input number is> 0. The extreme number in the sequence is 1. This is what I got:
def col(n): sp = [n] if n < 1: return [] while n > 1: if n % 2 == 0: n = n // 2 else: n = 3 * n + 1 sp.append(n) for i in sp: print(i, end = ' ') The interpreter outputs everything correctly (for the number 17 for example):
17 52 26 13 40 20 10 5 16 8 4 2 1 But the problem book does not pass the test.
https://stepik.org/lesson/Collatz-conjecture-or-the-3n-+-1-problem-21305/step/1?adaptive=true&unit=5105 Link to the task. What have I done wrong? I guess the problem is with the output.
return ' '.join(sp) I first did instead of prints, but in the list are numbers, not strings. Please advise.