python - 是什么阻止计算机向我的程序输出解决方案?

标签 python debugging

我正在用 python 编写代码,决定编写一个代码来查找平方数和三角形数并输出相同的数字,但是当我运行代码时没有输出。

源代码:

import math

s = 2
t = 1

while((s**2) != (t*(t+1)/2)):
 s = s + 1
 t = t + 1 


print (str(s) + " " + str(t))

最佳答案

首先,2**2 大于 1*(1+1)/2)
在while循环中,s和t都加1,使得两者的差别更大。
所以 while 循环是无限的,没有办法让它停止。因此,打印语句永远不会被执行。

关于python - 是什么阻止计算机向我的程序输出解决方案?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60330744/

相关文章:

python - 根据列中找到的阈值向上移动 DataFrame 列

python - 输出没有聚合的 Pandas 分组数据框

python - 属性错误 : 'list' object has no attribute 'children'

node.js - 如何通过 Google Cloud 调试在 Docker 容器中运行的 Nodejs 应用程序

javascript - 无论如何将 Firebug 'profile' 结果记录到外部文件?

python - numpy 数组中列表的索引

python - 如何使用python更新 Elasticsearch 文档?

python - 在列表中查找与另一个列表中的元素近似相等的元素的索引

macos - Applescript 更改 : copy the result as list isn't the same

swift - Xcode 无效的 Swift 可解析输出(格式错误的 JSON)