Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python triangular number

def triangular_number(n):
    return n * (n + 1) // 2  # Convert to int for Python 2
Comment

python triangular number

def triangular_number(n):
    for i in range(n):  # range(3) is a generator for [0, 1, 2]
        n += i
    return n
Comment

python triangular number

def triangular_number(n):
    i = n
    while True:
        if i == 1:
            return n
        i -= 1
        n += i
Comment

python triangular number

def triangular_number(n):
    return sum(range(n + 1))
Comment

python triangular number

def polygonal(n, sides):
    return (n**2*(sides-2) - n*(sides-4)) // 2

def triangular(n):
    return polygonal(n, 3)
Comment

python triangular number

polygonal(n, sides=3)
Comment

PREVIOUS NEXT
Code Example
Python :: .replace pandas in for loop 
Python :: subprocess the system cannot find the file specifie 
Python :: DJANGO model instance get by variable 
Python :: django query string route 
Python :: remove SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame 
Python :: python make dict 
Python :: re module python 
Python :: how to loop through every character in a string 
Python :: how to use with statement in python 2.5 and earlier 
Python :: python order list by multiple index 
Python :: from Player import Player 
Python :: append string variable with integer python 
Python :: pandas interpolate string 
Python :: Panda Python - Calculating what percentage of values are true and false out of total in boolean column 
Python :: python send email from icloud 
Python :: python get substring 
Python :: python db access though ssh user 
Python :: argparse parse path 
Python :: Python Print Variable Using the f-string in the print statement 
Python :: scrape pdf out of link 
Python :: pandas chesk if object is string or tuple 
Python :: how to comment python 
Python :: pandas check is field is null or empty 
Python :: open python file with read write permissions 
Python :: create a list of pandas index 
Python :: flask blueprints 
Python :: design patterns python 
Python :: convert to lwercase in df column 
Python :: python csv find specific string 
Python :: .dropna() python 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =