You are given a list with positive integers (int) and an integer (int) N. You should find the N-th power of the element in the list with the index N. If N is outside of the list, then return -1. Don't forget that the first element has the index 0.
Let's look at a few examples:
- list = [1, 2, 3, 4] and N = 2, then the result is 32 == 9;
- list = [1, 2, 3] and N = 3, but N is outside of the list, so the result is -1.
Input: Two arguments.A list of integers (int) and an integer (int).
Output: The result as an integer (int).
assert index_power([1, 2, 3, 4], 2) == 9 assert index_power([1, 3, 10, 100], 3) == 1000000 assert index_power([0, 1], 0) == 1 assert index_power([1, 2], 3) == -1
How it is used: This mission teaches you how to use basic arrays and indexes when combined with simple mathematics.
0 < len(array) ≤ 10
0 ≤ N
all(0 ≤ x ≤ 100 for x in array)
CheckiO Extensions allow you to use local files to solve missions. More info in a blog post.
In order to install CheckiO client you'll need installed Python (version at least 3.8)
Install CheckiO Client first:
pip3 install checkio_client
Configure your tool
checkio --domain=py config --key=
Sync solutions into your local folder
(in beta testing) Launch local server so your browser can use it and sync solution between local file end extension on the fly. (doesn't work for safari)
checkio serv -d
Alternatevly, you can install Chrome extension or FF addon
checkio install-plugin --ff
checkio install-plugin --chromium