Write function all_coprime_pairs( ) which takes as input a list, L, with positive unique integers (i.e. no duplicated integers), and should return:
1. List (of tuples) containing all pairs of numbers in L that are coprime.
2. Empty list, If no pair of numbers in L is coprime.
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.
My function coprime(x,y) is:
def coprime(x,y):
for i in range (2,x+1):
if x%i==0 and y%i==0:
return False
return True
###This is in Python###
PYTHON CODE:
import math
import math
def coprime(x,y):
for i in range (2,x+1):
if x%i==0 and y%i==0:
return False
return True
def all_coprime_pairs(L):
coprime_list = [] #create empty list
n = len(L)
for i in range(0,n-1):
for j in range(i+1,n): # we start the loop from i+1 so that we do not repeat the pairs added to list before
if(coprime(L[i],L[j])):
coprime_list.append((L[i],L[j])) #append the tuple to the list if both the numbers are coprime
return coprime_list
arr = [1, 2, 5, 4, 8, 3, 9]
all_coprime_pairs(arr)
OUTPUT:
(Note please refer the following screenshots in case of indentation error)
Write function all_coprime_pairs( ) which takes as input a list, L, with positive unique integers (i.e....
Python: Create a function count_target_in_list that takes a list of integers and the target value then counts and returns the number of times the target value appears in the list. Write program in that uses get_int_list_from_user method to get a list of 10 numbers, then calls the count_target_list method to get the count then prints the number of times the target was found in the list. def get_int_list_from_user(): lst=[] y = int(input("Enter number of numbers")) for x in range(y): lst.append(int(input("Enter...
Python Write a move function that takes a list of tuples, where each tuple is an x-y-z coordinate pair. This function should update the original list in-place to shift/move/translate the coordinates by an x_move, y_move, and z_move (respectively) and return None.
Use the FDR to design and write a function, maxValTimes, that takes a list of integers and returns a set containing the value(s) that occur the same number of times as the maximum value in the list. If the list is empty, return an empty set. For example if the list was [2,1,1,2,3,3,1] the function would return {2,3} as the maximum value is 3 which occurs twice, and 2 also occurs twice (but 1 occurs 3 times). For full marks,...
Write a function that takes, as an argument, a list of positive integers and a target value, and returns the number of times that the target value appears in the list. Call this function problem1(myList, target). For example, >>>problem1([1,2,3,4,5,6,5,4,3], 5) should return 2, and >>>problem1([1,2,3,4,5,6,5,4,3], 7) should return 0.
Python recursive function: Given an ordered list L. A permutation of L is a rearrangement of its elements in some order. For example (1,3, 2) and (3, 2, 1) are two different permutations of L=(1,2,3). Implement the following function: def permutations (lst, low, high) The function is given a list 1st of integers, and two indices: low and high (lows high), which indicate the range of indices that need to be considered The function should return a list containing all...
in python Part I: Sum of Odd Integers Write a recursive function sum-odds that takes a non-empty list of integers as an argument and returns the sum of only the odd integers in the list. In class we explored a recursive function called rsum that recursively computes the sum of a list of integers use it as a model to get started. Your function must be recursive and must not use any loops
The function below takes a single argument: data_list, a list containing a mix of strings and numbers. The function tries to use the Filter pattern to filter the list in order to return a new list which contains only strings longer than five characters. The current implementation breaks when it encounters integers in the list. Fix it to return a properly filtered new list. HW10.8. Fix code to filter only strings of a certain list from a collection The function...
Python 3.7.3 ''' Problem 3 Write a function called names, which takes a list of strings as a parameter. The strings are intended to represent a person's first and last name (with a blank in between). Assume the last names are unique. The function should return a dictionary (dict) whose keys are the people's last names, and whose values are their first names. For example: >>> dictionary = names([ 'Ljubomir Perkovic', \ 'Amber Settle', 'Steve Jost']) >>> dictionary['Settle'] 'Amber' >>>...
1 write a Python function that takes in a list of integers and returns maximum and minimum values in the list as a tuple. Hint (can be done in one pass, you are not allowed to use built-on min and max functions.)max, min = find_max_min(my_list):2 write a Python function that takes in a list of integers (elements), and an integer number (num). The functions should count and return number of integers in elements greater than, less than, and equal to...
Write a function that takes a list L = [a0,a1,....,an] of coefficients of a polynomial p(x) = a0xn+a1xn-1+...+ an as a single argument, factors the free coefficient , and prints all integer roots or an empty list if there is no integer roots in Python