I am attempting to create a function in Python 3.11.4 to simplify radical expressions; the first step is to find the closest perfect square below the number. To do this, I tried making a function that decreases the number by 1 each time, checks if the root is an integer, prints if it is, and goes to the next lowest number if not.
import math
def closest_perfect_square(radical):
while True:
rad_root = math.sqrt(radical)
if isinstance(rad_root, int):
print(rad_root)
else:
radical -= 1
closest_perfect_square(60)
Each time I run this program using any radical, it gives the ValueError: math domain error
. It would be much appreciated if anyone could help me figure out why it keeps giving me this error.