Contact search: where am I messing up? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
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 Respostas
+ 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