<prompt> Write a function to calculate the factorial of a given number.  <response>: Sure! Heres one way to write a function to calculate the factorial of a given number in Python:pythondef factorialn: Base case if n 1: return 1 Recursive case else: return n factorialn-1 Example: Calculate the factorial of 5num 5printfThe factorial of num is factorialnumThis function uses recursion, which means that it calls itself until the base case n 1 is reached. When the base case is reached, the function returns 1. Otherwise, the function will continue to call itself, multiplying n by the factorial of n-1 at each call, until the base case is reached. 