I have 2 lists , they are the same length and in correct order, what i need(i think) is that index of list1 is equal to index of list2 and print the list2 content at that index.
this is what i have so far:
id = [10610, 12772, 10611, 13434, 13397, 13854]
name = ['sarah', 'john', 'mark', 'james', 'jack']
userid = int(input('enter user ID: '))
ind = id.index(userid)
if userid in id:
print(ind)
else:
print('wrong ID')
output:
enter user ID: 13434
3
what i want it to do is, to print the content thats at the same index in "name" list, in this case its "james"
thanks
>Solution :
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