Mantaining order - Help!


#1

Please, help.

My code is:
"animals = ["aardvark", "badger", "duck", "emu", "fennec fox"]

duck_index = animals.index("duck")

animals.insert(duck_index, "corba")

print animals"

The mistake: " It looks like "cobra" is not at the correct location (index 4)."

Why it's not working?


#2

Why is there a double-quote before animals? That's incorrect. animals is supposed to be a list, not a string.

Look:

Look:

Another quotation mark after animals. That's not needed.


#3

There's no a double quote, I've just put it here to distinguish the code. Old habbit. So, there's no quote in my editor.

Look what I wrote:
duck_index = animals.index("duck")

animals.insert(duck_index, "corba")

So I defined duck_index and now the program knows it. And then I inserted "cobra" at that index.

Again, just for this forum. In the editor there's no quotation.


#4

My apologies for not replying so quickly, my Wi-Fi was broken all day yesterday and partly today, so that had to get fixed.

You're doing great! There's only one thing you need to fix....

Look at "corba", it isn't spelled right :slight_smile:


#5

Thank you, now it works


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.