有没有办法让我展示“想象中的”?负数或第 33 个整数之后缺少的任何数字?
# This is the original code beginning with the number 777 and I want to show the first 37 numbers.
def Collatz(n):
i = 1
while n != 1:
print(f'{i}. {n}')
if n & 1:
n = 3 * n + 1
else:
n = n // 2
i+=1
Collatz(777)
我想让它过去并停在第 37 个数字处。 (这可能意味着这些数字是虚数或负数。)
2
....
# This is the original code beginning with the number 777 and I want to show the first 37 numbers.
def Collatz(n):
i = 1
while n != 1:
print(f'{i}. {n}')
if n & 1:
n = 3 * n + 1
else:
n = n // 2
i+=1
Collatz(777)
I want it to go past and stop at the 37th number. (which probably means that the numbers are imaginary, or negative.)
2
....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没有更多数字可显示。它显示的
n
的最后一个值是 2。然后执行循环体,将
n
绑定到 1。然后循环就结束了,因为n != 1
不再正确。如果你继续下去,它就会永远重复 4, 2, 1, 4, 2, 1, 4, 2, 1, ...。
There are no more numbers to show. The last value of
n
it displays is 2. Then the body of loop executeswhich binds
n
to 1. The loop just ends then, becausen != 1
is no longer true.If you continued anyway, it would go on to repeat 4, 2, 1, 4, 2, 1, 4, 2, 1, ... forever.