code: def continued_fraction_convergents(cf):
      """
      Return an iterator over the convergents of a continued fraction (cf).
  
      The parameter should be in either of the following to forms:
      - A list of partial quotients, possibly with the last element being a list
      of repeating partial quotients, such as might be returned by
      continued_fraction and continued_fraction_periodic.
      - An iterable returning successive partial quotients of the continued
      fraction, such as might be returned by continued_fraction_iterator.
  
      In computing the convergents, the continued fraction need not be strictly
      in canonical form (all integers, all but the first positive).
      Rational and negative elements may be present in the expansion.
  
      Examples
      ========
  
      >>> from sympy.core import pi
      >>> from sympy import S
      >>> from sympy.ntheory.continued_fraction import \
              continued_fraction_convergents, continued_fraction_iterator
  
      >>> list(continued_fraction_convergents([0, 2, 1, 2]))
      [0, 1/2, 1/3, 3/8]
  
      >>> list(continued_fraction_convergents([1, S('1/2'), -7, S('1/4')]))
      [1, 3, 19/5, 7]
  
      >>> it = continued_fraction_convergents(continued_fraction_iterator(pi))
      >>> for n in range(7):
      ...     print(next(it))
      3
      22/7
      333/106
      355/113
      103993/33102
      104348/33215
      208341/66317
  
      >>> it = continued_fraction_convergents([1, [1, 2]])  # sqrt(3)
      >>> for n in range(7):
      ...     print(next(it))
      1
      2
      5/3
      7/4
      19/11
      26/15
      71/41
  
      See Also
      ========
  
      continued_fraction_iterator, continued_fraction, continued_fraction_periodic
  
      """
      if isinstance(cf, list) and isinstance(cf[-1], list):
          cf = itertools.chain(cf[:-1], itertools.cycle(cf[-1]))
      p_2, q_2 = S.Zero, S.One
      p_1, q_1 = S.One, S.Zero
      for a in cf:
          p, q = a * p_1 + p_2, a * q_1 + q_2
          p_2, q_2 = p_1, q_1
          p_1, q_1 = p, q
          yield p / q
  
file_path: sympy/sympy/ntheory/continued_fraction.py
imports: from __future__ import annotations
  import itertools
  from sympy.core.exprtools import factor_terms
  from sympy.core.numbers import Integer, Rational
  from sympy.core.singleton import S
  from sympy.core.symbol import Dummy
  from sympy.core.sympify import _sympify
  from sympy.utilities.misc import as_int
label_desc: Use image node_id 5 for calling a global function with example usage: continued_fraction_convergents(cf) without return types