''' Purpose: continue introduction to functions ''' 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 is_prime( x ) : ''' Parameter x is an integer. The function returns whether x is prime; i.e., its only factors are 1 and itself. ''' result = True # initialize it outside of the loop, only update it if you find a factor for i in range( 2, x ) : if ( is_factor(x, i) == True ) : # check if i is a factor of x, if it is then x is not prime by definition # we can use the is_factor() function to make our lives easier, this is part of why we use functions result = False # can't have an else here, because if i is not a factor of x that does not ensure prime 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. ''' # there are three possibilities. x is a factor of y, y is a factor of x, or they are relatively prime if ( is_factor( x, y ) == True ) : result = False elif ( is_factor( y, x ) == True ) : result = False else : result = True return result