[Solved] python: index of list1 equal to index of list2 [duplicate]


well what the comments said and change it like the following too :

    id = [1, 2, 3, 4, 5, 6]

    name = ['sarah', 'john', 'mark', 'james', 'jack']

    userid = int(input('enter user ID: '))

    if userid in id:
        ind = id.index(userid) #notice this statement is inside the if and not outside
        print(name[ind])
    else:
        print("wrong id")

if you try to use inden(..) before checking if the userid (the one they entered) is in the id , then you will get ValueError: <some-numer> is not in list

so its better to do it inside the if

solved python: index of list1 equal to index of list2 [duplicate]