Here I wrote the following code to search for headers from an excel sheet, it can search for the headers, but for each successful iteration, it prints success separately and also same for the error.
for i in sheet_data:
if (i[0] == "BN") and (i[1] == "YOU"):
found_list.append(i)
print("Success")
else:
print("error")
>
error
error
error
Success
error
Success
error
error
If the iteration found the string at once or twice then print success only once hence it will not print error. If there is no success iteration then only it has to print error (else) once. (I just need to print success or error)
You are always printing something when you are testing, use a temporary variable and print the result after scanning the full list:
success = False
for i in sheet_data:
if (i[0] == "BN") and (i[1] == "YOU"):
found_list.append(i)
success = True
if success:
print("Success")
else:
print("error")