Given a list of rational numbers,find their product. Concept The reduce() function applies a function of two arguments cumulatively on a list of objects in succession from left to right to reduce it to one value. Say you have a list, say [1,2,3] and you have to find its sum. >>>reduce(lambdax,y:x+y,[1,2,3])6 You can also define an initial value. If it is specified, the function will assume initial value as the value given, and then reduce. It is equivalent to adding the initial value at the beginning of the list. For example: >>>reduce(lambdax,y:x+y,[1,2,3],-3)3>>>fromfractionsimportgcd>>>reduce(gcd,[2,4,8],3)1 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 . Sample Input 0 31 23 410 6 Sample Output 0 5 8
Given a list of rational numbers,find their product.
Concept
The reduce() function applies a function of two arguments cumulatively on a list of objects in succession from left to right to reduce it to one value. Say you have a list, say [1,2,3] and you have to find its sum.
You can also define an initial value. If it is specified, the function will assume initial value as the value given, and then reduce. It is equivalent to adding the initial value at the beginning of the list. For example:
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 .
Sample Input 0
Sample Output 0
Step by step
Solved in 3 steps with 2 images