
Exercise 763
Write a python algorithm as function which take as argument an integer n and return the list of all tuples (p , q) of positive integers p and q shch that the Euclidean division of p by q gives 3 as the quotient and 2 as the remainder.
Solution
def listTuples(n):
# Initializing the list of all tuples (p,q)
listTup = []
for i in range(1 , n + 1):
for j in range(1 , i + 1):
if (i%j == 2 and i//j == 3):
listTup.append((i,j))
return listTup
# Testing algorithm for n = 24
print('The list of all tuples (p,q) is : ' , listTuples(24))
# The output is : The list of all tuples (p,q) is : [(11, 3), (14, 4), (17, 5), (20, 6), (23, 7)]
Younes Derfoufi
my-courses.net
my-courses.net