0

Contact search: where am I messing up?

contact = "" contacts = [ ('James', 42), ('Amy', 24), ('John', 31), ('Amanda', 63), ('Bob', 18) ] for contact in contacts: if contact == contacts[0]: print (contacts[0] + " is " + (contacts[1])) else: print ("Not found")

12th May 2021, 5:27 PM
Chris
Chris - avatar
2 Réponses
+ 1
You need a new variable to be what you are searching for. As you have written it, you are probably not getting the desired results. Make a new var for your input. inp = input(). Then replace contacts[0] in both places with inp. That lets you specify what you are search for. Then, because it’s an array. You’ll need to use contact as an array. So change contact to contact[0] inside the if statement. So it will read, if contact[0] == inp: and change that print statement as well so it uses inp and contact[0].
12th May 2021, 5:38 PM
Jerry Hobby
Jerry Hobby - avatar
0
First step is to ask yourself what result you want to achieve with this code...
12th May 2021, 5:28 PM
Tomas Konecny