What is python program for Factorial of numbers?? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
0

What is python program for Factorial of numbers??

I mean How one can make a factorial (From Maths) program in python i.e, factorial of 5 means 5! =5×4×3×2×1 or 7! =7×6×5×4×3×2×1

9th Sep 2017, 1:10 AM
Sarveshwar Shukla
Sarveshwar Shukla - avatar
1 Réponse
+ 1
You can use a recursive function like this: def factorial(n): print("factorial has been called with n = " + str(n)) if n == 1: return 1 else: res = n * factorial(n-1) print("intermediate result for ", n, " * factorial(" ,n-1, "): ",res) return res print(factorial(5)) I think the print statements explain it better than I could
9th Sep 2017, 2:02 AM
Enzo
Enzo - avatar