Square at Alternate Indices
Given an array
input:
[1,2,3,4,5]
output:
[1,2,9,4,25]
input:
[2,4]
output:
[4,4]
list1 = [1, 2, 3, 4, 5]
def fun_square_odd(input_array):
"""Squares the odd input of given array"""
for item in list1:
if list1.index(item) % 2 == 0:
ind = list1.index(item)
list1[ind] = item * item
print(list1)
fun_square_odd(list1)
Comments
Leave a comment