Cody Bable

Generation

generate functionWed, 12 Apr 2023

create a main driver than repeatedly calls collatz() and determines the length of the returned list.

def collatz(num): vals = [num] while num > 1: if num % 2 == 0: num /= 2 else: num = num * 3 + 1 vals.append(int(num)) return vals

Questions about programming?Chat with your personal AI assistant