mystr = "BEGIN here is some text END BEGIN END"words = mystr.split() k_begin = 0k_end = 0 print("My string was =")print(mystr) for word in words: print(f"\nMy word = {word}") if word == "BEGIN": k_begin += 1 elif word == "END": k_end += 1 B = (k_begin == k_end) print("B =", B)
Standard input is empty
My string was = BEGIN here is some text END BEGIN END My word = BEGIN My word = here My word = is My word = some My word = text My word = END My word = BEGIN My word = END B = True
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!