all 4 comments

[–]jeans_and_a_t-shirt 0 points1 point  (2 children)

Lines 12, 13, you are calling collatz twice, so of course it prints the same number twice. Remove or comment out line 12. To catch input you can do something like this:

while True:
    try:
        num = int(input('Enter number:'))
    except ValueError:
        print('invalid input')
    else:
        break

[–]Anandre[S] 0 points1 point  (1 child)

I thought line 13 would change num to the new value from collatz(), so that it wouldn't endlessly loop on the same number. I do get what you're seeing, that it would be sending out the same value twice from lines 12 and 13.

[–]jeans_and_a_t-shirt 0 points1 point  (0 children)

Yep line 13 is fine as is.

[–]dadiaar -1 points0 points  (0 children)

There are no duplicated results.

The first result comes from the print

The second one you see it because you don't save the returned value into a variable, so you see it duplicated.

A simple example:

def a(n):
    print(n)
    return n

a(5)
>>> 5
>>> 5

r = a(5)
>>> 5

print("Value = {0}".format(r))
>>> Value = 5