Click here to Skip to main content
15,946,012 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Length of int(b**0.5) is always coming to be 1, this is the problem.

If the no. Will be perfect it's root length will be small and if it is not a perfect square then it will be in decimal and it's root length will be big.

What I have tried:

Python
Def square():
    a=int(input("Enter the no."))

    b=int(a**0.5)
    If Len(b)==1 or Len(b)==2:
        Print("the number is a perfect square")

    Elif Len(b)>3:
        Print("is not perfect square") 

#Its not working.
Posted
Updated 18-Aug-22 22:12pm
v3
Comments
Patrice T 18-Aug-22 14:02pm    
How "Its not working.", give details
Richard Deeming 19-Aug-22 3:47am    
"if it is not a perfect square then it will be in decimal"

So why are you casting the square root to an int then?

1 solution

Pretty much every line of code is incorrect. It looks as if you have been trying to write VB.NET statements with Python expressions. Python is a case sensitive language and all statements and builtin functions use lower case. You also do not need to check the length of b, but its value from the previous expression. You also do not need to check if it is greater than 3 (actually should be greater than 2) since if it is not 1 or 2 then it must be greater than 2. So go to The Python Tutorial — Python 3.10.6 documentation[^] and study the proper syntax of the language. Then think about what you need to do to correct your code.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900