Learn about Check if Number is Perfect Square in Python using Function in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.
Check if Number is Perfect Square in Python using Function
# Program to check number is perfect square or not #importing math-module import math def PerfectSquare(x): root = math.sqrt(x) if int(root + 0.5) ** 2 == x: print(x, 'is a perfect square') else: print(x, 'is not a perfect square') return root # input from user num = int(input('Enter number: ')) # function call PerfectSquare(num)
Enter number: 16
16 is a perfect square
Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.
Similar Code : Python Program to Check Whether a Number is a Perfect Square