绍兴柯桥哪里有做网站的,空调seo是什么意思,广州建筑工程公司有哪些,做企业网站的流程CheckiO 是面向初学者和高级程序员的编码游戏#xff0c;使用 Python 和 JavaScript 解决棘手的挑战和有趣的任务#xff0c;从而提高你的编码技能#xff0c;本博客主要记录自己用 Python 在闯关时的做题思路和实现代码#xff0c;同时也学习学习其他大神写的代码。
Chec…
CheckiO 是面向初学者和高级程序员的编码游戏使用 Python 和 JavaScript 解决棘手的挑战和有趣的任务从而提高你的编码技能本博客主要记录自己用 Python 在闯关时的做题思路和实现代码同时也学习学习其他大神写的代码。
CheckiO 官网https://checkio.org/
我的 CheckiO 主页https://py.checkio.org/user/TRHX/
CheckiO 题解系列专栏https://itrhx.blog.csdn.net/category_9536424.html
CheckiO 所有题解源代码https://github.com/TRHX/Python-CheckiO-Exercise 题目描述
【Index Power】给定一个数组 array 和一个整数 n求该数组 n 位置元素的 n 次方如果整数 n 大于数组的长度则输出 -1 如果数组 n 位置元素为 0则输出 1.
【链接】https://py.checkio.org/mission/index-power/
【输入】两个参数一个数组一个整数。
【输出】计算结果整数
【范例】
代码实现
def index_power(array: list, n: int) - int:Find Nth power of the element with index N.if n len(array):return array[n] ** nelse:return -1if __name__ __main__:print(Example:)print(index_power([1, 2, 3, 4], 2))#These asserts using only for self-checking and not necessary for auto-testingassert index_power([1, 2, 3, 4], 2) 9, Squareassert index_power([1, 3, 10, 100], 3) 1000000, Cubeassert index_power([0, 1], 0) 1, Zero powerassert index_power([1, 2], 3) -1, IndexErrorprint(Coding complete? Click Check to review your tests and earn cool rewards!)大神解答 大神解答 NO.1 def index_power(array: list, n: int) - int:Find Nth power of the element with index N.if n len(array):for x in array[n:n1]:return x**nelse:return -1大神解答 NO.2 def index_power(array: list, n: int) - int:Find Nth power of the element with index N.return array[n]**n if len(array) n else -1