code: def semiconvergents(x):
      
  
      (q, n), d = divmod(x.numerator, x.denominator), x.denominator
      yield Fraction(q)
      p0, q0, p1, q1 = 1, 0, q, 1
      while n:
          (q, n), d = divmod(d, n), n
          for _ in range(q):
              p0, q0 = p0+p1, q0+q1
              yield Fraction(p0, q0)
          p0, q0, p1, q1 = p1, q1, p0, q0
docs: Semiconvergents of continued fraction expansion of a Fraction x.