🚀 Hurry! Offer Ends In
00 Days
00 Hours
00 Mins
00 Secs
Enroll Now
X

Python में factorial निकालने के लिए सबसे अच्छा तरीका क्या है?

What is the best way to calculate factorial in Python?

A
Using loop only
B
Using a recursive function
C
Using print statement
D
Using input() function
Explanation

Python में factorial निकालने के कई तरीके हैं, लेकिन एक classical और elegant तरीका है — recursive function का उपयोग करना।

A recursive function is a function that calls itself to solve smaller instances of the same problem — perfect for factorials.


🔹 Recursive factorial function का उदाहरण:

def factorial(n):
    if n == 0 or n == 1:
        return 1
    else:
        return n * factorial(n - 1)

print(factorial(5))  # Output: 120

 

Correct Answer: B) Using a recursive function

Latest Updates