''' Purpose: continue introduction to functions Name: Email id: Who checked your code: Whose code did you check: ''' def is_factor( x, y ) : ''' Parameters x and y are integers. The function returns whether y is a factor of x. ''' # compute remainder of x divided by y rem = x % y # check it out if ( rem == 0 ) : # check whether remainder is 0 result = True # if it is, return value is True else: result = False # if it is not, return value is False # return determination return result def are_relative_primes( x, y ) : ''' Parameters x and y are integers. The function returns whether x and y are relatively prime; i.e., whether y is not a factor of x and vice-versa. ''' # determine whether y is a factor of x b1 = is_factor( x , y ) # determine whether x is a factor of y b2 = is_factor( y , x ) # look at determinations if ( b1 == True ): result = False elif ( b2 == True ): result = False else: result = True return result def is_prime( x ) : ''' Parameter x is am integer. The function returns whether x is prime; i.e., its only factors are 1 and itself. ''' result = True for i in range( 2 , x ): b = is_factor( x , i ) if ( b == True ): result = False return result return result if __name__ == "__main__": import primal a1, b1 = 6, 2 a2, b2 = 7, 3 a3, b3 = 4, 5 f1 = primal.is_factor( a1, b1 ) f2 = primal.is_factor( a2, b2 ) f3 = primal.is_factor( a3, b3 ) print( 'is_factor(', a1, ',' , b1, ') = ', f1 ) print( 'is_factor(', a2, ',' , b2, ') = ', f2 ) print( 'is_factor(', a3, ',' , b3, ') = ', f3 )