input: Write a function to rewrite the given code snippet that finds prime numbers using Python. Ensure that the function checks if a number is prime by iterating from 2 to the square root of the number. Then, use this function to iterate from 2 to n and print all prime numbers within this range.
  assert is_prime(2)==True
  assert is_prime(3)==True
  assert is_prime(4)==False
  assert is_prime(5)==True
  assert [n for n in range(2, 10) if is_prime(n)]==[2, 3, 5, 7]
output: def is_prime(n):
      if n <= 1:
          return False
      for i in range(2, int(n**0.5) + 1):
          if n % i == 0:
              return False
      return True