I am a complete python beginner and I am trying to solve this problem :
A number is called triangular if it is the sum of the first n positive integers for some n For example, 10 is triangular because 10 = 1+2+3+4 and 21 is triangular because 21 = 1+2+3+4+5+6. Write a Python program to find the smallest 6-digit triangular number. Enter it as your answer below.
I have written this program:
n = 0
trinum = 0
while len(str(trinum)) < 6:
trinum = n*(n+1)/2
n += 1
print(trinum)
And it only works in the python I have installed on my computer if I say while len(str(trinum)) < 8:
but it is supposed to be while len(str(trinum)) < 6:
. So I went to http://www.skulpt.org/ and ran my code there and it gave me the right answer with while len(str(trinum)) < 6:
like it's supposed to. But it doesn't work with 6 with the python i have installed on my computer. Does anyone have any idea what's going on?