15/15 help please


#1

hi my code works but it returns the value in a list inside [ ] and keeps returning an error. how can i get rid of the [ ]


#2

@atlantaspp: When you assign something in brackets, [] , to variable, it will turn into a list.

newVariable = [ listA[1] + listB[1]] # Will generate another list containing the value
#you get after adding the elements that are stored in the index 1 of each list.
newVariable = listA[1] + listB[1] #Won't generate a new list, will only have the value of the addition.

I think generateis a strong word for this but just know you'll get another list if you do like the first example.


#4

No problem, Pierrepp! Glad to help!


#5

i tired that but it still saying same thing again


#6

@atlantaspp: That's because you're returning the list whenever the length of is one.
Return the actual value on it, since it's just one element,it should be lst[0]

But note:

If you are given a sequence with an even number of elements, you must average the two elements surrounding the middle.

Does your code works if the length of your list is an odd number?