Sort by

recency

|

208 Discussions

|

  • + 0 comments

    This is easy one and simple logic! The one fraction value in fracs is passed to x and another passed to y. Then it will multiplied and remaining also multiplied with answer. now we get multiplication of fraction. This value is reduced using reduce() to find numerator and denominator

    from fractions import Fraction
    from functools import reduce
    
    def product(fracs):
        t = reduce(lambda x,y: x*y,fracs)
        return t.numerator, t.denominator
    
    if __name__ == '__main__':
        fracs = []
        for _ in range(int(input())):
            fracs.append(Fraction(*map(int, input().split())))
        result = product(fracs)
        print(*result)
    
  • + 0 comments
    def product(fracs):
        pro = fracs[0]
        for frac in fracs[1:]:
            pro *= frac
        return pro.numerator, pro.denominator
    
  • + 0 comments
    from fractions import Fraction
    from functools import reduce
    from math import gcd
    
    def product(fracs):
        pro = fracs[0]
        for frac in fracs[1:]:
            pro *= frac
        t = reduce(gcd,[pro])
        return t.numerator, t.denominator
    
    
    if __name__ == '__main__':
        fracs = []
        for _ in range(int(input())):
            fracs.append(Fraction(*map(int, input().split())))
        result = product(fracs)
        print(*result)
    
  • + 0 comments

    from fractions import Fraction from functools import reduce def product(fracs): t = reduce (lambda x, y : x * y, fracs) return t.numerator, t.denominator if name == 'main': fracs = [] for _ in range(int(input())): fracs.append(Fraction(*map(int, input().split()))) result = product(fracs) print(*result)

  • + 0 comments

    def product(fracs):

        t =reduce(lambda x,y : x*y,fracs)  ** # complete this line with a reduce statement**
    return t.numerator, t.denominator