Open the context
Choose the project folder and name the files or behavior involved.
Return every convergent of a continued fraction with one through 32 integer coefficients bounded by 1000 in magnitude. Test a negative first term and 3-7-16, rejecting nonpositive later terms and keeping numerator-denominator pairs exact.
Choose the project folder and name the files or behavior involved.
Describe the input, expected output and boundaries that must stay intact.
Review the proposed edits and any commands before relying on their result.
Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.
def convergents(terms):
terms = tuple(terms)
if not 1 <= len(terms) <= 32 or any(type(a) is not int or abs(a) > 1000 for a in terms):
raise ValueError("fraction.terms")
if any(a <= 0 for a in terms[1:]):
raise ValueError("fraction.tail")
p0, p1, q0, q1, out = 0, 1, 1, 0, []
for a in terms:
p, q = a*p1+p0, a*q1+q0
out.append((p, q))
p0, p1, q0, q1 = p1, p, q1, q
return outThe example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.