Write a Python lambda function that calculates the factorial of a number. Return the factorial.
Example 1:
Input: 5
Output: 120
Example 2:
Input: 6
Output: 720
Use a recursive approach within the lambda function to calculate the factorial.
# Define the lambda function
factorial = lambda n: 1 if n == 0 else n * factorial(n-1)
# Test the function
print(factorial(5)) # Output: 120
print(factorial(6)) # Output: 720
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.