Hi Guys,

Please be gentle with me as im a complete n00b. My favorite language is actually Java which im learning at Uni at the moment. However to throw a spanner in the works they have switched us over to Python, as well as learning Java. My mind has been completely boggled. I just need to understand this for the moment and Im hoping someone out there will be kind enough to help me. I have created a list with names in, and i want to delete what ever name i wish to do so. So i have put a for loop in there. Now I can delete any name WITHOUT the if-statement in there but when i put if statements in there so set either condition to be true or false it doesnt do what i want it to. here is my code:

Any ideas? Thanks :-)

   def main():
       for i in range(len(names)):
           print names
           a = raw_input("Choose name to be deleted:\n")
           print "name deleted"
           print "No such name!Please Re-enter!"

For starters, you have declared names to be a tuple containing one list so you would access it with
e=names[i][0]. But anyway, your code cleaned up a bit.

for nm in names:
    print nm

while True:  ## infinite loop until break is called
    a = raw_input("Choose name to be deleted:\n")
    if a in names:
        print "name deleted"
        print "No such name!Please Re-enter!"
This question has already been answered. Start a new discussion instead.