human
Product of given N fractions in reduced form | Function to return gcd of a and b.
Print the Product of N fraction in Reduced Form ..
finding the product of all N numerators and denominators ..
Finding GCD of new numerator and denominator.
Converting into reduced form ..
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to product of given N fractions in reduced form and the other steps required.
 def gcd ( a , b ) :
	if ( a == 0 ) :
		return b ;
	return gcd ( b % a , a ) ;
def productReduce ( n , num , den ) :
	new_num = 1 ;
	new_den = 1 ;
	for i in range ( n ) :
		new_num = new_num * num [ i ] ;
		new_den = new_den * den [ i ] ;
	GCD = gcd ( new_num , new_den ) ;
	new_num = new_num / GCD ;
	new_den = new_den / GCD ;
	print ( int ( new_num ) , " / " , int ( new_den ) ) ;
n = 3 ;
num = [ 1 , 2 , 5 ] ;
den = [ 2 , 1 , 6 ] ;
productReduce ( n , num , den ) ;