-1

I have written the python code below to create a database:

list = ["a","b","c","d","e"]



while(True):
  print("1/insert")
  print("2/delete")
  print("3/quit")
  print("4/display")

  choice=int(input("enter your choice: "))

  if choice==1:
    name=input("enter a name:")
    list.insert(1,name)

  if choice==2:
    dltname=input("enter the name you want to delete")
    list.remove(dltname)

  if choice == 3:
    exit()
  if choice==4:
    
    print(list)

When I first insert an item, it's inserted in the 1st index position, my goal is when I insert the next item, I want to insert it in the 3rd index positon, the next one in the 5th index positon, means I want to insert each item in the next available odd index position. Can I get help about how to do this? Thank you!

I tried to use n=1 whose value increases by 2 every time 1 is chosen as option, but couldn't do it.

Zac Anger
  • 6,983
  • 2
  • 15
  • 42
  • The first tag you should add when asking a code-related question is for the language that you're using. It helps get the question in front of people who can answer it. Please [edit] your post to add that tag. – Ken White Nov 28 '22 at 03:25

1 Answers1

-1
Help on method_descriptor:

insert(self, index, object, /)
    Insert object before index.

insert(1, obj) will insert the object before index 1 which will turns to be the 2th position after insert opt.

marco
  • 24
  • 3