Write a function in Python myRelationpq that prints the set

Write a function in Python, myRelation(p,q), that prints the set of ordered pairs of the following relation:

r = {(x,y) | x A, y B, x divides y, x + y > p, x + y < q}

where A: set of odd numbers = {1, 3, 5, 7, 9, . . .};

B: set of even numbers = {2, 4, 6, 8, 10, . . .};

p and q are input parameters of your function (p < q, p > 3, and q > 4).

Examples:

myRelation(5,10) will print the ordered pairs: (1,6), (1,8), (3,6)

myRelation(6,15) will print the ordered pairs: (1,6), (1,8), (1,10), (1,12), (3,6)

Solution

def myfunction(p,q):
x = 1;
y = 2;
print \"(x,y) are:)
check(x,y,p,q);
return;

def check(x,y,p,q):
sum = int(x) + int(y);
if (sum > p and sum < q and y % x = 0):
print \"( %d, %d)\", % (x,y)
y = y + 2;
check(x,y,p,q);
elif (sum <= p or y%x != 0):
y = y + 2;
check(x,y,p,q)
elif (sum >= q):
x = x + 2;
y = y + 2;
check(x,y,p,q)
}
if (x > q){
return;
}

return;

Write a function in Python, myRelation(p,q), that prints the set of ordered pairs of the following relation: r = {(x,y) | x A, y B, x divides y, x + y > p, x

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site