product of digit of number in python by R4R Team

program-

import functools
print("Enter number")
num=input()

#first way
n=int(num)
ans=1
while(n):
ans=ans*(n%10)
n=int(n/10)
print("Product of digit is",ans)

#second way
n=num
li=list(map(int,','.join(n).split(",")))
ans=functools.reduce(lambda x,y:x*y,li)
print("Product of digit is",ans)


output-

Enter number
1234
Product of digit is 24
Product of digit is 24

Enter number
818
Product of digit is 64
Product of digit is 64


-In this program, we take a input then in first method we split digit one by one and multiple then print
-In second way, we split digit of number and store in list, then using reduce() we find the product of items in list.




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!