#split 7 from sys import stdin the_str = "" while(True): new_char = stdin.read(1) if new_char == '' and test_candidate == '': break test_candidate = the_str + new_char if int(test_candidate) % 7: #print test_candidate, "is a multiple of 7 continuing" the_str = test_candidate else: #print "adding", new_char, "didnt work, printing previous candidate" print test_candidate the_str = ''