Have been given this challenge, called Double Index under Python Lists
Create a function named
double_index that has two parameters named
The function should double the value of the element at
lst and return the new list with the doubled value.
index is not a valid index, the function should return the original list.
My code is:
def double_index(lst, index): try: lst[index] = 2 * lst[index] except IndexError: lst[index] = lst[index] return lst
I have tried it out with multiple values and it seems to work - why wont it be accepted?