Answer to Question #259296 in Python for Villaan

Question #259296

Write a program 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.


Else print No perfect Square

1
Expert's answer
2021-10-31T12:01:17-0400
import math

line = input()
words = line.split()
if len(words) > 1:
    M = int(words[0])
    N = int(words[1])
else:
    M = int(line)
    N = int(input())

x = int(math.sqrt(M)) 
if x*x == M:
    print(M)
elif (x+1)*(x+1) <= N:
    print((x+1)*(x+1))
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