Question

In: Computer Science

Two numbers a and b are called pythagorean pair if both a and b are integers...

Two numbers a and b are called pythagorean pair if both a and b are integers and there exists an integer c such that a2 + b2 = c2. Write a function pythagorean_pair(a,b) that takes two integers a and b as input and returns True if a and b are pythagorean pair and False otherwise.

Solutions

Expert Solution

def pythagorean_pair(a,b):
        c = (a*a + b*b) ** 0.5
        return c ** 2 == int(c) ** 2

print(pythagorean_pair(3, 4))
print(pythagorean_pair(6, 7))
print(pythagorean_pair(6, 8))
**************************************************

Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.

Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.


Related Solutions

Three positive integers (a, b, c) with a<b<c are called a Pythagorean triple if the sum...
Three positive integers (a, b, c) with a<b<c are called a Pythagorean triple if the sum of the square of a and the square of b is equal to the square of c. Write a program that prints all Pythagorean triples (one in a line) with a, b, and c all smaller than 1000, as well the total number of such triples in the end. Arrays are not allowed to appear in your code. Hint: user nested loops (Can you...
An integer n is said to be Pythagorean if there exist two nonzero integers x and...
An integer n is said to be Pythagorean if there exist two nonzero integers x and y such that x2 + y2 = n2 . Present an O(n) time algorithm to check if a given integer n is Pythagorean or not. Assume that you can nd the square root of any number in O(1) time.
Let a and b be integers. Recall that a pair of Bezout coefficients for a and...
Let a and b be integers. Recall that a pair of Bezout coefficients for a and b is a pair of integers m, n ∈ Z such that ma + nb = (a, b). Prove that, for any fixed pair of integers a and b, there are infinitely many pairs of Bezout coefficients.
Write a method called printIsMultiple that receives a pair of integers and prints true if the...
Write a method called printIsMultiple that receives a pair of integers and prints true if the second is a multiple of the first; false, otherwise
Write a Python program called arecongruent.py that determines whether two integers a and b are congruent...
Write a Python program called arecongruent.py that determines whether two integers a and b are congruent modulo n. Your code must work as follows: From the command prompt the user runs the program by typing python arecongruent.py and then your program interface prompts the user for the values of a, b, and n. The program outputs either True or False, and the values of a mod n and b mod n. Submit your Python source code arecongruent.py. NOTE: please include...
a.) Prove the following: Lemma. Let a and b be integers. If both a and b...
a.) Prove the following: Lemma. Let a and b be integers. If both a and b have the form 4k+1 (where k is an integer), then ab also has the form 4k+1. b.)The lemma from part a generalizes two products of integers of the form 4k+1. State and prove the generalized lemma. c.) Prove that any natural number of the form 4k+3 has a prime factor of the form 4k+3.
A Pythagorean triplet is a set of positive integers (x, y, z) such that x2 +...
A Pythagorean triplet is a set of positive integers (x, y, z) such that x2 + y2 = z2. Write an interactive script that asks the user for three positive integers (x, y, z, in that order). If the three numbers form a Pythagorean triplet the script should a) display the message ‘The three numbers x, y, z, form a Pythagorean triplet’ b) plot the corresponding triangle using red lines connecting the triangle edges. Hint: place the x value on...
Let a and b be integers which are not both zero. (a) If c is an...
Let a and b be integers which are not both zero. (a) If c is an integer such that there exist integers x and y with ax+by = c, prove that gcd(a, b) | c. (b) If there exist integers x and y such that ax + by = 1, explain why gcd(a, b) = 1. (c) Let d = gcd(a,b), and write a = da′ and b = db′ for some a′,b′ ∈ Z. Prove that gcd(a′,b′) = 1.
Theorem 3.4. Let a and b be integers, not both zero, and suppose that b =...
Theorem 3.4. Let a and b be integers, not both zero, and suppose that b = aq + r for some integers q and r. Then gcd(b, a) = gcd(a, r). a) Suppose that for some integer k > d, k | a and k | r. Show that k | b also. Deduce that k is a common divisor of b and a. b) Explain how part (a) contradicts the assumption that d = gcd(b, a).
The Fibonacci Sequence is a series of integers. The first two numbers in the sequence are...
The Fibonacci Sequence is a series of integers. The first two numbers in the sequence are both 1; after that, each number is the sum of the preceding two numbers. 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ... For example, 1+1=2, 1+2=3, 2+3=5, 3+5=8, etc. The nth Fibonacci number is the nth number in this sequence, so for example fibonacci(1)=1, fibonacci(2)=1, fibonacci(3)=2, fibonacci(4)=3, etc. Do not use zero-based counting; fibonacci(4)is 3, not 5. Your assignment...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT