Python 中的最大 Collat​​z 长度,但输出不正确

Maximum Collatz length in Python, but output is not correct

这是我第一次在 Whosebug 上发帖。

我正在尝试解决此问题:https://codingbat.com/prob/p270692?parent=/home/konstans@stuy.edu/all

When looking at all hailstone sequences from 1 to z, maxHail(z) will return the starting number that creates the longest sequence. In other words, maxHail(n) looks at hailLen(1), hailLen(2) ... hailLen(n) and returns the number from 1-n that had the largest hailstone sequence. You should look at the hailLen() problem before working on this. You should use your solution from the hailLen() problem. ( http://codingbat.com/author/p264289 ) since hailLen(3) is larger than the hailLen of 4 or 5, maxHail of 3,4,5 all return 3. Since 6 has a longer sequence, maxHail(6) gives us 6. remember: Use the hailLen function you already wrote!

这是我的代码和输出:

但是,我不确定哪里出了问题 - 我逐行检查,没有发现任何错误。谁能帮我解决这个问题?谢谢!

我知道出了什么问题 - hailLen returns 序列长度,问题是关于序列最长的索引。只需将其存储在变量

if (res := hailLen(i)) > counter: # it's python 3.8 syntax
    counter = res
    index = i
return index