from math import log10 with open("przyklad.txt", "r") as file: line = file.readline().strip() potegi3 = 0 while line != "": dec = int(line) l = log10(dec) / log10(3) if l == int(l): potegi3 += 1 line = file.readline().strip() save = open("wyniki.txt", "w") save.write(str(potegi3))