Answer to Question #243524 in Python for Rishi

Question #243524
Give two integers M and N write a program to print the first perfect square in a given range
1
Expert's answer
2021-09-28T07:25:16-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