[INST] Refactor this code and add comments./ndef factorialize(num):
  factorial = 1
  for i in range(1, num):
    factorial *= i
  
  return factorial [/INST]  ###Response: ```
# This is a function that calculates the factorial of a given number
def factorialize(num):
  # Set the variable 'factorial' to 1
  factorial = 1
  # Iterate from 1 to 'num' using the range function
  for i in range(1, num):
    # Multiply the 'factorial' variable by the current number in the iteration
    factorial *= i
  # Return the final value of 'factorial'
  return factorial
```