Nombre triangulaire python
def triangular_number(n):
return n * (n + 1) // 2 # Convert to int for Python 2
Travinth Dayalaeaswaran
def triangular_number(n):
return n * (n + 1) // 2 # Convert to int for Python 2
polygonal(n, sides=3)
def triangular_number(n):
i = n
while True:
if i == 1:
return n
i -= 1
n += i
def triangular_number(n):
return sum(range(n + 1))
def polygonal(n, sides):
return (n**2*(sides-2) - n*(sides-4)) // 2
def triangular(n):
return polygonal(n, 3)
def triangular_number(n):
for i in range(n): # range(3) is a generator for [0, 1, 2]
n += i
return n