Python program to Get Sum and Products of Digits

str1 = str(input("Insert values only: "))
sum_digit = 0
pro_digit = 1
for x in str1:
 if x.isdigit() == True:
  z = int(x)
 sum_digit = sum_digit + z
 pro_digit *= z
print("Sum of digits = ",sum_digit)
print("Product of digits = ", pro_digit)

 

 

Output:

Insert values only: 123
Sum of digits =  6
Product of digits =  6

 

Insert values only: 435
Sum of digits =  12
Product of digits =  60

Subscribe For Daily Updates