我是一个完整的python初学者,我正在尝试解决这个问题:
如果数字是某些n的前n个正整数之和,则称为三角形.例如,10是三角形,因为10 = 1 + 2 + 3 + 4,21是三角形,因为21 = 1 + 2 + 3 + 4 + 5 + 6.编写一个Python程序来查找最小的6位三角形数字.在下面输入它作为您的答案.
我写了这个程序:
n = 0
trinum = 0
while len(str(trinum)) < 6:
trinum = n*(n+1)/2
n += 1
print(trinum)
Run Code Online (Sandbox Code Playgroud)
它只能在我安装在计算机上的python中工作,如果我说while len(str(trinum)) < 8:但它应该是while len(str(trinum)) < 6:.所以我去http://www.skulpt.org/并在那里运行我的代码,它给了我正确的答案,while len(str(trinum)) < 6: 就像它应该的那样.但它与我在我的计算机上安装的python不兼容6.有谁知道发生了什么事?