This article is originally posted on programmingeeksclub. You’ll see the following output whenever you run the above code: $ python main.py Factorial of 5 is 120 Factorial using for range loop def factorial(n): print("user input is: ".format(userInput, fac)) I already mentioned that python have while and for range loop so first we’re going to write our program to find factorial of n number in python using for range loop, you can also can it for in loop. The easiest way is to use math.factorial (available in Python 2.6 and above): import math math. You’ll see the while and for loop example below of Factorial Program in Python Factorial Program in Python using Loop
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |