Answered You can hire a professional tutor to get the answer.

QUESTION

1_Implement a function coprime described below. The function takes as input two positive integers x and y and returns True if x and y are coprimes...

1_Implement a function coprime described below. The function takes as input two positive integers x and y and returns True if x and y are coprimes and False otherwise. Two positive integers x and y are said to be coprime if the only positive integer that divides both of them is 1. That is, the only common positive factor of the two numbers is 1.

def coprime(x,y): '''(int,int)->bool Precondition: x and y are both positive integers >>> coprime(1,7) True >>> coprime(21,14) False >>> coprime(14,15) True >>> coprime(7,7) False'''

2_Write the body of the function all_coprime_pairs described below. The function takes as input a list, L, of positive distinct integers (that is, no two integers in L are the same). The function should return a list (of tuples) containing all pairs of numbers in L that are coprimes. If no pair of numbers in L is coprime, the function should return an empty list. Your solution must include a function call to the function coprime designed in the previous question. The order of the tuples or the order of the two numbers within the tuples is not important.

def all_coprime_pairs(L): '''(list)->list_of_tuples Precondtion: L is a list of positive distinct integers and len(L)>=2 >>> all_coprime_pairs([21,1, 7,14, 15]) [(21, 1), (1, 7), (1, 14), (1, 15), (7, 15), (14, 15)] >>> all_coprime_pairs([18,6,9]) []

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question