To find the n-th square number in Python, we can simply use the formula n^2. Here's a function that takes an integer n and returns the n-th square number:
main.py40 chars3 linesWe can then call this function with any integer value of n to get the corresponding square number. For example:
main.py54 chars5 lines
Note that the formula works because the square of an integer n is the same as n multiplied by itself. So n^2 is always the n-th square number.
gistlibby LogSnag