7. Help I have no idea what is wrong with my code


#1




Error message: Oops, try again. It looks like there may have been a problem with insert() or index(). Double check them!


animals = ["aardvark", "badger", "duck", "emu", "fennec fox"]
duck_index =animals.index("duck")    # Use index() to find "duck"

# Your code here!
print duck_index.index("duck")
animals.insert(duck_index, "cobra")

print animals # Observe what prints after the insert operation


#2

bruh, i'm lost. i retyped and rearranged and reread and re-re'd erythang bro, i'm dun


#3

just get rid of this line and you should be fine. I don't know why you have it there.


#4

animals = ["aardvark", "badger", "duck", "emu", "fennec fox"]
duck_index = animals.index("duck") # Use index() to find "duck"

Your code here!

animals.insert(duck_index,"cobra")

print animals # Observe what prints after the insert operation


#6

Hi, could you help me, pls, cause i really don't understand what can be wrong here..

animals = ["aardvark", "badger", "duck", "emu", "fennec fox"]
duck_index = animals.index("duck") # Use index() to find "duck"
print duck_index
""" Your code here!"""
animals.insert(2, "cobra")

print animals # Observe what prints after the insert operation

Error: Make sure to pass duck_index as the first argument in insert().

Thanks


#7

animals = ["aardvark", "badger", "duck", "emu", "fennec fox"]
duck_index = animals.index("duck") # Use index() to find "duck"

Your code here!

animals.insert(duck_index, "cobra")

print animals # Observe what prints after the insert operation

Since the index "duck" was already found and defined as duck_index, you dont need to put down 2 because duck_index has already found what location "duck" is.


#8

Thanks, but I have found already the reason )
Anyway thank you for your reply.


#9

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