Hello programmers,
Need a help on check if there is any other way to code the below code to find out if the number entered by a user is a perfect square or not?
print(“Enter a number to see if it is a perfect square or not”)
num = input()
num = eval(num)
i = -1
square = False
while num >=0 and num%1 == 0:
i = num ** (0.5)
if i * i == num:
square = True
break
i = i+1
if square:
print(‘It is a square.’ + 'The square root of the given number is: ', i)
else:
print(‘Not a square’)
If there is an effective way of writing this. Please post it as a reply.
Thanks.