In the code above, we define a method `octagonal_number` that takes an integer `n` as an argument and returns the nth octagonal number.
The formula for finding the nth octagonal number is `n(3n-2)`. We implement this formula inside the method andreturn the result.
In the example, we call the method with an argument of 5 to find the 5th octagonal number and print the result, which is 141.