0

not working? It goes through each one then print output but not print Not Found unless the input name is not in list at all.

Contact =[('James', 42), ('Amy', 24), ('John', 31), ('Amanda', 63), ('Bob', 18)] a=0 name = input() for x in contacts: If name in x: print(str(x[0]) + " is " + str(x[1]) break elif a < 4: a += 1 else: print("Not Found")

13th Jul 2022, 8:12 PM
Cindy Nelson
5 Respostas
+ 4
Most of the Python keywords and built-in functions are written in lowercase. It makes a huge difference.
13th Jul 2022, 8:17 PM
Tibor Santa
Tibor Santa - avatar
+ 4
the list of tuples (names and ages) is stored with the variable name *contact*, but in the for loop *contacts* is used btw: the line that outputs the result can be done easier and without converting the ages to a string, if you use a comma to separate the print arguments: (sample) ... number = 42 print("size: " + str(number)) # <<< instead of using this print("size:",number ) # <<< do it like this
13th Jul 2022, 8:24 PM
Lothar
Lothar - avatar
+ 1
Two more problems: 1. When you test 'if name in x', remember x is a tuple with name and a number. If a testcase enters an existing number, your code will return the corresponding name, instead of "Not found". 2. The indentation is wrong. The elif and else statements are linked to the for loop, when they should be to the if statement.
14th Jul 2022, 7:26 PM
Emerson Prado
Emerson Prado - avatar
0
That not it. It keep printing not found before print the name and age.
13th Jul 2022, 9:02 PM
Cindy Nelson
0
Test case #5 is the only one that does not have green check mark and it is locked. I am assuming that it should be Not Found as the answer.
13th Jul 2022, 9:34 PM
Cindy Nelson