Clifford Werner
Clifford Werner

Reputation: 1

python code syntax error with my .index () in code

i am doing this homework problem in whichthis code is to retrieve a search input from user such a name or phone and it will print out the info from a list in the code. I have no idea i keep getting an syntax error at where the varible "place" first appears

place = int(name.index(search))

I honestly have no idea why this is happening, may be just my ignorance on using the functions

contact = [["John","Steve","Jane", "Sally","Pam"],["999-555-1122","999-444-2233", "999-333-3344","999-222-4455", "999-111-5566"],["[email protected]","[email protected]","[email protected]","[email protected]","[email protected]"]]
name    = contact[0]
phone   = contact[1]    
email   = contact[2]
n=0
while n == 0:
    command = str(input("Choose command (list,name,number,email,add,remove,quit):"))
    if   command == ("list"):
        print (contact)
    elif command == ("name"):
        search = str(input("Input name:")
        place= int(name.index(search))
        if search in name:
            print("Contact Found")
            print (name[place])
            print (phone[place])
            print (email[place])
        else:
            print("Contact could not be found")
    elif command == ("number"):
        search = str(input("Input name:")
        place  = int(name.index(search))
        if search in name:
            print("Contact Found")
            print (name[place])
            print (phone[place])
        else:
            print("Contact could not be found")

    elif command == ("email"):
        search = str(input("Input name:")
        place  = int(name.index(search))
        if search in name:
            print("Contact Found")
            print (name[place])
            print (email[place])
        else:
            print("Contact could not be found")
    elif command == ("add"):
        print ("Adding New Contact:")
        newname  = str(input("Name :"))
        newphone = str(input("Phone:"))
        newemail = str(input("Email:"))
        name.append(newname)
        phone.append(newphone)
        email.append(newemail)
    elif command == ("remove"):
        contactdel= str(input("Which contact information would you like to remove?"))
        if contactdel in name:
            confirm = str(input("Are you sure you want to delete this contact?(y or n)"))
            if confirm == ("y"):
                contactfind=name.index(contactdel)
                name.pop([contactfind])
                phone.pop([contactfind])
                email.pop([contactfind])
                print ("Contact has been sucessfully deleted")
            elif confirm == ("n"):
                print ("Contact will not be deleted")
            else:
                print ("ERROR.....INPROPER INPUT.....ERROR")

    elif command == ("quit"):
        n = 1

Upvotes: 0

Views: 62

Answers (1)

tdelaney
tdelaney

Reputation: 77357

Syntax errors are frequently a bit higher up the code than the point where python finally realizes something has gone wrong. In your case, look up one line to

search = str(input("Input name:")

Its missing a final closing paren at the end.

When I'm having problems spotting a syntax error, I paste just a small bit of the offending code into a separate file and hack away from there. For instance, this script produces the same problem and its a lot easier to spot the problem

search = str(input("Input name:")
place  = int(name.index(search))

Upvotes: 1

Related Questions