Question

Problem 4 (a) Write a function is_sum_squares (n) that returns True if n can be written as a² + b2 , where a, b are integers,please use python to solve

0 0
Add a comment Improve this question Transcribed image text
Answer #1
# Part a
def is_sum_square(n):
    for i in range(n+1):
        for j in range(n+1):
            if i*i+j*j==n:
                return True
    return False

# Part b
# Testing
print(is_sum_square(7))
print(is_sum_square(11))
print(is_sum_square(13))
print(is_sum_square(17))
print(is_sum_square(19))
print(is_sum_square(23))

# part c
# when p is prime and p%4 is 1 then is_sum_of(p) is True

Output:

False False True True False False

Note: Please comment below if you have any doubts. upuote the solution if it helped. Thanks!

Add a comment
Know the answer?
Add Answer to:
please use python to solve Problem 4 (a) Write a function is_sum_squares (n) that returns True...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • in python A. Define a function called contains_only_integers() that takes a tuple, returns True if all...

    in python A. Define a function called contains_only_integers() that takes a tuple, returns True if all the items in the tuple are integers(2), and returns False otherwise. For example, contains_only_integers (3, 5, 17, 257, 65537) ), contains_only_integers( (-1,) ), and contains_only_integers( ) should all return True, but contains_only_integers (2.0,4.0)) and contains_only_integers (8, 4, "2", 1)) should both return false. Your function should use a while loop to do this calculation. 121 Hint: the is instance() built-in function provides the most...

  • How to solve it using Python? 5. Write a function called no_squares which takes an input...

    How to solve it using Python? 5. Write a function called no_squares which takes an input parameter N, a positive integer, and returns: 1 if N is not divisible by a square and has an even number of prime factors -1 if N is not divisible by a square and has an odd number of prime factors 0 if N is divisible by a square For example, no-squares (10) returns 1 (since 10 = 2x5), no-squares (30) returns-1 (since 30...

  • USE PYTHON PLEASE Write a function called is prime which takes a single integer argument and...

    USE PYTHON PLEASE Write a function called is prime which takes a single integer argument and returns a single Boolean value representing whether the given argument is prime (True) or not (False). After writing the function, test it by using a loop to print out all the prime numbers from 1-100. To check your results, the prime numbers from 1-100 are: 2, 3, 5, 7, 11. 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67,...

  • Python: Write a function subsetSum() that takes as input a list of positive number and a...

    Python: Write a function subsetSum() that takes as input a list of positive number and a positive number target. The function returns True if there are three numbers in the list that add up to the target. For example, the list [5, 4, 10, 20, 15, 19] and targert 38, then True is returned since 4 + 15 + 19 = 38. However, the list [5, 4, 10, 20, 15, 19] and target 5 returns False. >>> subsetSum([5, 4, 10,...

  • PYTHON 3 - please show format Question 2. ) Use the Design Recipe to write a...

    PYTHON 3 - please show format Question 2. ) Use the Design Recipe to write a function yesOrNo which has no parameters. When called, it gets input from the user until the user types either 'yes' or 'no', at which point the function should return True if the user typed 'yes' and False if the user typed 'no'. Any other entries by the user are ignored and another value must be input. For example: Test Input Result print(yesOrNo()) hello blank...

  • Write a Python function isPrime(number) that determines if the integer argument number is prime or not....

    Write a Python function isPrime(number) that determines if the integer argument number is prime or not. The function will return a boolean True or False. Next, write a function HowManyPrimes(P), that takes an integer P as argument and returns the number of prime numbers whose value is less than P. And then write a function HighestPrime(K) that takes integer K as an argument and returns the highest prime that is less than or equal to K. USE THE WHILE LOOP...

  • In PYTHON: Write a function that receives a list of integers and returns the number of...

    In PYTHON: Write a function that receives a list of integers and returns the number of integers that are larger than the element immediately before them. For example, given [1,2,3,-5,0,-5,-10] the function should return 3 (since 1<2, 2<3, and -5<0).

  • Please use python 3 programming language Write a function that gets a string representing a file...

    Please use python 3 programming language Write a function that gets a string representing a file name and a list. The function writes the content of the list to the file. Each item in the list is written on one line. Name the function WriteList. If all goes well the function returns true, otherwise it returns false. Write another function, RandomRange that takes an integer then it returns a list of length n, where n is an integer passed as...

  • IN PYTHON: Write a function that takes, as an argument, a positive integer n, and returns...

    IN PYTHON: Write a function that takes, as an argument, a positive integer n, and returns a LIST consisting of all of the digits of n (as integers) in the same order. Name this function intToList(n). For example, intToList(123) should return the list [1,2,3].

  • ****python**** Q1. Write a recursive function that returns the sum of all numbers up to and...

    ****python**** Q1. Write a recursive function that returns the sum of all numbers up to and including the given value. This function has to be recursive; you may not use loops! For example: Test Result print('%d : %d' % (5, sum_up_to(5))) 5 : 15 Q2, Write a recursive function that counts the number of odd integers in a given list. This function has to be recursive; you may not use loops! For example: Test Result print('%s : %d' % ([2,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT