floor = 0 with open("input", encoding="utf-8") as f: text = f.read() for char in text: if char == '(': floor += 1 elif char == ')': floor -= 1 print(f"floor is {floor}")