Question #243524

Give two integers M and N write a program to print the first perfect square in a given range

Expert's answer

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!

LATEST TUTORIALS
APPROVED BY CLIENTS