Hi everyone! I have look for other discussions, but I have not found this problem, I hope to not ask something already answered.
So, the exercise states: Create a function named
double_index that has two parameters: a list named
lst and a single number named
The function should return a new list where all elements are the same as in
lst except for the element at
index . The element at
index should be double the value of the element at
index of the original
index is not a valid index, the function should return the original list.
After some difficulties in the understanding what I was supposed to do, I came out with this code:
#Write your function here def double_index(lst,index): ind= lst[index] *2 #this is the double index if ind<=len(lst): lst = lst[0:index] + lst[index+1:] lst.append(ind) return lst else: #elif ind>len(lst): return lst
I have tried it, and it works!
My problem is that, when I check my answer, this is what it came out: “Make sure to define what should happen if
index is too big!”.
I have also tried the elif in the comment, but the result is the same. I have checked and if I put an invalid index, it returns the original list (as it is stated in bold). So I am a little bit lost, am I misunderstanding the challenge? Am I missing something? Am I crazy?
Please, help this poor soul!