Input Format
First line contains , the number of rational numbers.
The  of next  lines contain two integers each, the numerator(  ) and denominator(  ) of the  rational number in the list.
Constraints
Output Format
Print only one line containing the numerator and denominator of the product of the numbers in the list in its simplest form, i.e. numerator and denominator have no common divisor other than .

hackerrank reduce function problem solution in python programming

Problem solution in Python 3 programming language.

from fractions import Fraction

def product(fracs):
    t = reduce(lambda x, y: x*y, fracs)
    return t.numerator, t.denominator

if __name__ == '__main__':
    fracs = []
    for _ in range(input()):
        fracs.append(Fraction(*map(int, input().split())))
    result = product(fracs)
    print(*result)

Second solution

from fractions import Fraction
from functools import reduce
import operator
def product(fracs):
    t =  reduce(operator.mul , fracs)
    return t.numerator, t.denominator
if __name__ == '__main__':
    fracs = []
    for _ in range(int(input())):
        fracs.append(Fraction(*map(intinput().split())))
    result = product(fracs)
    print(*result)

Problem solution in Python 2 programming language.

from __future__ import print_function
from fractions import Fraction

def product(fracs):
    t = reduce(lambda x, y: x*y, fracs)
    return t.numerator, t.denominator

if __name__ == '__main__':
    fracs = []
    for _ in range(input()):
        fracs.append(Fraction(*map(int, raw_input().split())))
    result = product(fracs)
    print(*result)