input: Write a function to find all perfect numbers up to a given number n.
  assert perfect_numbers(10) == [6]
  assert perfect_numbers(100) == [6, 28]
  assert perfect_numbers(500) == [6, 28, 496]
output: def perfect_numbers(n):
      def is_perfect(num):
          return num == sum(i for i in range(1, num) if num % i == 0)
  
      return [num for num in range(2, n + 1) if is_perfect(num)]