In this example, we will create a python function that will return an even number based on the Nth even number given.

Let say when we enter one into that function, the function will return 0 because the first even number is 0. If we enter two into that function, the function will return 2 because the second number of even numbers is 2. Besides that, we will also need to take care of the number that is smaller than 1 which is an invalid entry as one is the very first even number.

def nth_even(n): if n < 1: return 0 # return the first even number if the user has entered an invalid number else: return 2 * (n-1) [/php]

Enter your own solution in the comment box below!

Please follow and like us:

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *