Write a Python function that calculates the factorial of a number. The function should accept a number as an argument and return the factorial.
Example 1:
Input: 5
Output: 120
Example 2:
Input: 3
Output: 6
Use recursive approach to solve this problem. The factorial of a number n is n times the factorial of (n-1).
def factorial(n):
if n == 1 or n == 0:
return 1
else:
return n * factorial(n - 1)
NOTEOwing to browser caching, any code input into the Trinket IDE might carry over across page refreshes or when transitioning between different questions. To commence with a clean slate, either click on the 'Reset Button' found within the IDE's Hamburger icon (☰) menu or resort to using Chrome's Incognito Mode.