0
How do not an error (else out of if)
contacts = [ ('James', 42), ('Amy', 24), ('John', 31), ('Amanda', 63), ('Bob', 18) ] nam=input() for x in contacts : if nam in x: print (nam+" is "+str(x[1])) break else: print ("Not Found")
3 Answers
+ 3
You're missing the print part if the condition is true
+ 2
Unlike other languages, Python invented the use of `else` conditional for loops.
Please refer the below docs link, the 4.4 section in particular - "4.4 break and continue Statements, and else Clauses on Loops"
https://docs.python.org/3/tutorial/controlflow.html
+ 1
Thank you so much