0
Need a help in Contact Search problem
Here’s my code: contacts = [ (‘James, 42), (‘Amy’ ,24), (‘John’, 31), (‘Amanda’, 63), (‘Bob’, 18) ] name = input() name_list = list() for i in range(5): name_list += contacts[i][0] if name in name_list: for x in range(5): if name == contacts[x][0]: print(“{} is {}”.format(name, contacts[x][1])) else: print(“Not found”) /// Problem is, I always get “Not found” as an output whether the name is in the list or not. I know it’s a complicated code, but why doesn’t it work?
3 Answers
+ 1
contacts = [
('James', 42),
('Amy', 24),
('John', 31),
('Amanda', 63),
('Bob', 18)
]
text = input()
for i in contacts:
if text in i:
print(str(i[0]) + " is " + str(i[1]))
break
if text not in i:
print("Not found")
+ 1
contacts = [
('James', 42),
('Amy', 24),
('John', 31),
('Amanda', 63),
('Bob', 18)
]
text=input()
for i in contacts:
if text in i:
print(str(i[0]) + " is " + str(i[1]))
break
if text not in i:
print("Not Found")
/// I think I have solved ur problem. ...:)
0
try " if name not in name_list: " instead of else :)