0
Issue with the tuple coding exercise?
Tuple coding exercise issue even with the solution that solo learn provides. contacts = [ ('James', 42), ('Amy', 24), ('John', 31), ('Amanda', 63), ('Bob', 18) ] name= input() for x in contacts: if name in x: print(str(x[0])+" is "+str(x[1])) break elif x not in contacts: print("Not Found")
3 ответов
+ 8
# Try this code.
# Hint: the else block will not be executed if the loop is stopped by a break statement.
for x in contacts:
if name in x:
print(x)
break
else:
print("Not Found")
+ 1
It should be
elif name not in x
Basically just "else" statement would do the same
0
Try this:
x=input()
count=0
for i in contacts:
if i[0]==x:
print (f"{x} is {i[1]}")
count+=1
if count==0:
print ("Not Found")
#as we need to write “Not Found” only once, we can’t print it while looping. Thats why we should print it in another condition “if”:)