0

I'm new to python, so I'm having trouble with something that I think is easy, but I'm not getting anywhere.

I basically want to find the square root of a number, and if its a perfect square, print it.

this is a rough estimate of what I'm trying to do.

import random
import math
x = int(random.randint(0, 100000)
y = int(math.sqrt(x)
if y == int:
    print(y)
  • `if y == int(y):` – Barmar Nov 09 '22 at 23:08
  • But there's likely to be roundoff error, so this won't always work. – Barmar Nov 09 '22 at 23:08
  • I don't think your code matches your title. You're testing if the square root is an integer, which would tell you if the original number is a perfect square. You're not testing if the root is a square. – Barmar Nov 09 '22 at 23:10

0 Answers0