Answer to Question #175898 in Python for jayanth

Question #175898

First Perfect Square

Given two integers (M and N), write a program to print the first perfect square in a given range.Input


The first line of input will contain a positive integer (M).

The second line of input will contain a positive integer (N).Output


The output should be a single line containing the first perfect square in a given range.Explanation


For example, if the given numbers are M is 4 and N is 16, the perfect squares from 4 to 16 are 4(2 * 2), 9(3 * 3), and 16(4 * 4), as the first perfect square is 4. So the output should be 4.

Sample Input 1

4

16

Sample Output 1

4

Sample Input 2

5

8

Sample Output 2

No Perfect Square




1
Expert's answer
2021-03-27T00:16:49-0400
def Squares(a, b):
  
    for i in range (a, b + 1):
        j = 1;
        while j * j <= i:
            if j * j == i:
                 yield j*j
            j = j + 1
        i = i + 1

a = int(input("Enter lower bound:"))
b = int(input("Enter upper bound:"))


x = [v for v in Squares(a,b)]
if x:
    print(min(x))
else:
    print("No perfect square")

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS