You can find the nth triangular number by using the formula n * (n + 1) / 2
. Here's how you can implement this in Python:
main.py121 chars6 lines
In this code, //
is used instead of /
to ensure that the result of the division is an integer, as triangular numbers are usually defined as integers.
gistlibby LogSnag