Calculadora de Fracciones
Suma, resta, multiplica y divide fracciones con soluciones paso a paso.
Fracción 1
Operación
Fracción 2
Preguntas Frecuentes
Implementación de Código
from fractions import Fraction
import math
# Python's built-in Fraction class handles exact rational arithmetic
a = Fraction(1, 3) # 1/3
b = Fraction(1, 4) # 1/4
print(a + b) # 7/12
print(a - b) # 1/12
print(a * b) # 1/12
print(a / b) # 4/3
# Auto-simplification
print(Fraction(8, 12)) # 2/3 (auto-simplified)
print(Fraction(6, 4)) # 3/2
# Mixed numbers
mixed = Fraction(2) + Fraction(3, 4) # 2 + 3/4
print(mixed) # 11/4
print(int(mixed), mixed - int(mixed)) # 2 3/4
# Manual implementation
def gcd(a, b):
return math.gcd(abs(a), abs(b))
def lcm(a, b):
return abs(a * b) // math.gcd(a, b)
def add_fractions(n1, d1, n2, d2):
common = lcm(d1, d2)
result_n = n1 * (common // d1) + n2 * (common // d2)
g = gcd(result_n, common)
return result_n // g, common // g
print(add_fractions(1, 3, 1, 4)) # (7, 12)
# Comparing fractions
f1 = Fraction(3, 7)
f2 = Fraction(2, 5)
print(f1 > f2) # True (3/7 > 2/5 since 15 > 14)Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.