Exercise 753

Write a python algorithm as a function which takes as argument a positive integer n and returns the list of all the tuples (u, v) of integers such that: u2 + v2 <= n.

Solution

def allTuples(n):
# Initializing the list of searched tuples
solutionTuples = []
for u in range(0, n+1):
for v in range(0,n+1):
if u**2 + v**2 <= n:
solutionTuples.append((u,v))
return solutionTuples
# Testing algorithm
print("The searched list of n = 23 is : " , allTuples(23))

Younes Derfoufi
my-courses.net

Leave a Reply