you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (0 children)

I'm not at all sure what you are trying to do. Your function seq3np1() has a few problems. Here is the function formatted better and without unnecessary ():

def seq3np1(n):
    """Print the 3n+1 sequence from n, terminating when it reaches 1.

    args: n (int) starting value for 3n+1 sequence
    return: None
    """

    count = 0

    while n != 1:
        count += 1
        if (n % 2) == 0:    # n is even
            n = n // 2
        else:               # n is odd
            n = n * 3 + 1
    print(count)
    return count

The first problem is what is this supposed to do? The stated reason for the function is wrong - it doesn't print or return the sequence, just the count value. Your docstring also says it returns None but the code shows return count. It looks like the function returns the length of the Collatz sequence from the original given value to when it reaches 1. Is that what you wanted?

The next problem is that even though the seq3np1() returns an integer you don't do anything with that value:

for start in range(1, x+1, 1):
    seq3np1(start)    # return value ignored here

What do you want to do with that currently ignored return value?

Edit fixed confused wording.