Double Index Code


#1

hello everyone !

I’m new to coding, and I’m not a native english speaker, so maybe it is the problem. So far I had no problem understanding and learning the very basics of python, but it seems I have a really hard time understanding what this exercise want me to do. I think all theses “index” really confuse me !
If someone have the patience to explain to me a little more clearly what I’m suppose to achieve, I would be really glad !

Thanks !

Create a function named double_index that has two parameters named lst and index .
The function should double the value of the element at index of lst and return the new list with the doubled value.
If index is not a valid index, the function should return the original list.

https://www.codecademy.com/paths/computer-science/tracks/cspath-flow-data-iteration/modules/dspath-lists/lessons/python-functions-lists-cc/exercises/double-index


#2

What i useally do is split it in smaller problems or just rewrite the problems in a more readable way.

for example:

  • Create a function named double_index
    example: def functionname()
  • give this function two parameters named lst and index
    example: def functionname(lst, index)
  • The function should double the value of the element at index of lst
    example: lst[index] = lst[index]*2
  • the function should return the new list with the doubled value.
    example: return lst
  • If index is not a valid index, the function should return the original list.
pseudo:
if index is not a number:
    return lst

hope it helps.


#3

Hi, thank you for your help.

I got confused by the " The function should double the value of the element at index of lst" part of the exercices. Had a hard time to figure out what it meant :
you take the number at that position in the list and double its value.
It wasn’t really clear for me at the time that “index” means that. Kind of obvious now :stuck_out_tongue:

Spending some time on it with your answer made it clear.