''' Purpose: continue introduction to functions ''' def is_factor( x, y ) : ''' Determines whether y is a factor x ''' # print( a1, b1 ) This won't work because a1 and b1 are variables over in the main code, so they don't exist # in this function rem = x % y if ( rem == 0 ) : result = True else: result = False return result def are_relative_primes( x, y ) : ''' Determines whether x and y are relatively prime; i.e., whether y is not a factor of x and vice-versa ''' y_is_factor_of_x = is_factor( x, y ) x_is_factor_of_y = is_factor( y, x ) if ( y_is_factor_of_x == True ): result = False elif ( x_is_factor_of_y == True ): result = False else: result = True return result def is_prime( x ) : ''' Determines whether x is a prime number; i.e., its only factors are 1 and itself ''' # have I found any reason to suspect x is not prime? No result = True # I need to check all numbers between 2 and n-1 to see if they are factors for y in range( 2, x ): y_is_factor_of_x = is_factor( x, y ) # y_is_factor_of_x is already a boolean value, so you don't need to include "== True" if you don't want to if ( y_is_factor_of_x == True ): result = False # Could just return False here, since we already know the answer now else: # Don't change anything if you don't find a factor pass return result