def fibonacci(): a, b = 1, 1 while True: yield a a, b = b, a + b def fib_digit(digit): for i, value in enumerate(fibonacci()): if len(str(value)) == digit: return i + 1 print(fib_digit(1000))