Find Factorial by Numpy Python by R4R Team


program-

#import numpy
import numpy as np

n=int(input("Enter any numbern"))
ans=np.product([i for i in range(1,n+1)])
print("Factorial of number is :",ans)


output-

Enter any number
5
Factorial of number is : 120

Enter any number
4
Factorial of number is : 24

Enter any number
6
Factorial of number is : 720


-In this program, we take a input of the integer number, then run loop from 1 to the given number, and make list like [1,2,3,4,5,......] then using np.product(), we multiple all elements of the list and that will be the required factorial.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!