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")

23rd Aug 2023, 7:27 PM
Cristian Chavez
Cristian Chavez - avatar
3 Antworten
+ 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")
23rd Aug 2023, 9:05 PM
JaScript
JaScript - avatar
+ 1
It should be elif name not in x Basically just "else" statement would do the same
24th Aug 2023, 4:08 PM
Toni Isotalo
Toni Isotalo - avatar
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”:)
29th Dec 2024, 10:18 AM
Ivan Gaiduk