(adsbygoogle = window.adsbygoogle || []).push({ google_ad_client: "ca-pub-2960223314593660", enable_page_level_ads: true }); Program to check whether the given number is a perfect square or not - TecGlance

Header Ads

Program to check whether the given number is a perfect square or not


Program to check whether the given number is a perfect square or not

x=input("Enter the number : ")
ans = 0
if x >= 0:
    while ans*ans < x:
        ans = ans + 1
    if ans*ans != x: 
        print x, "is not a perfect square."
    else:
        print x, " is a perfect square."


OUTPUT :

  
Enter the number :  16
16  is a perfect square.
  
Enter the number :  25
25  is a perfect square.
  
Enter the number :  24
24 is not a perfect square.

No comments

Powered by Blogger.