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 RĂ©ponses
+ 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 :)