Wednesday 28 June 2023

Factorial Python Program

Here's a small Python example that calculates the factorial of a given number using recursion def factorial(n): if n == 0: return 1 else: return n * factorial(n-1) # Example usage number = 5 result = factorial(number) print("The factorial of {number} is: ",result)





Description : In this example, the factorial function takes an integer 'n' as input and calculates its factorial recursively. The base case is when 'n' is equal to 0, in which case the function returns 1. Otherwise, it multiplies 'n' by the factorial of n-1. The example then demonstrates the usage of the factorial function by calculating the factorial of 5 and printing the result. When executed, the output will be: ('The factorial of {number} is: ', 120)

No comments:

Post a Comment

Odoo 17 New Features

  Odoo 17 new Features 1) Duplicate  multiple records from List view. Please have look below screenshots first you need to select records th...