0
As far as I know, else should be below the if, corresponding it, but in the code below, Else is not next to the if , because it is outside the repeating structure, to be more exact, the else is not even identado, so the same was always to be executed and this does not happen. And yet the code works perfectly!
L=[7,9,10,12]
p=int(input("Digite um número a pesquisar:"))
for e in L:
if e == p:
print("Elemento encontrado!")
break
else:
print("Elemento não encontrado.")
In Python the command
formay have a clauseelse. See the documentation.– anonimo
Reading the documentation helps a lot. This is from
for .. elseand not ofif .. else.– Bacco
vlw guys, helped a lot was already getting crazy kkk
– relaie