Open the context
Choose the project folder and name the files or behavior involved.
Reduce a fraction of two integers to a positive denominator and coprime terms. Check a negative denominator and a zero numerator, rejecting a zero denominator and non-integer operands before reduction.
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.
from math import gcd
def reduce_fraction(numerator, denominator):
if any(type(v) is not int for v in (numerator, denominator)):
raise ValueError("integer.required")
if denominator == 0:
raise ValueError("denominator.zero")
if denominator < 0:
numerator, denominator = -numerator, -denominator
divisor = gcd(numerator, denominator)
return numerator // divisor, denominator // divisorThe 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.