 License MIT license
 Lines 20
##### Keywords euler (1) math (4) number (1) triangle (2)
##### Related Python __Underscore__ Methods Calculate PI to 17 Million Digits Logit function Triangle Primitives by Ideambulate Pretty Prints a Tree of Dictionaries in Python
##### Permissions Owner: clawlor Viewable by Everyone Editable by clawlor's Friends

# Test if an integer is a triangle number 0

 In Brief A triangular number is the sum of the n natural numbers from 1 to n.... more
 Language Python
# 's
` 1def istriangle(n): 2	""" 3	Tests if n is a triangle number. 4	Input: 5		n -- a positive integer 6	Output: 7		a positive integer indicating which triangle number in the series is n, 8		or False if n is not a triangle number 9	Examples:10	>>> istriangle(1)11	112	>>> istriangle(55)13	1014	>>> istriangle(7)15	False16	"""17	x = (math.sqrt(8*n + 1) - 1) / 218	if x - int(x) > 0: # if x is not an integer19		return False20	return int(x)`

A triangular number is the sum of the n natural numbers from 1 to n.

Returns False if n is not a triangle number. If n is a triangle number, returns an integer indicating which triangle number in the series is n.