-2

The numbers in the sequence generated by the Collatz function will be put in a string. Building this string is likely the hardest part of this. Get the computation working without worrying about creating the string. Now, I'm sure I'm getting logically correct output, I need the help to create the string containing all the numbers, separated by a comma and space characters.

enter image description here

Danlin
  • 1

1 Answers1

0

result is not concatenated.

def Collatz(number):
    result = ''
    while number != 1:
        ...
        ...
        print(number)
        if result:
            result = str(number)
        else:
            result += ', ' + str(number)
    return result

    n = get_input()
    result = Collatz(n)
    print(result)
user3713719
  • 325
  • 3
  • 8