n0 = 10000 list = [] list.append(n0) # limit = 0 while True: cur = list[-1] if cur % 2 == 0: list.append(cur / 2) else: list.append(3 * cur + 1) if list[-1] == 1: break # limit += 1 # if limit > 500: # break print(int(max(list)))