Subtract the Product and Sum of Digits of an Integer - LeetCode
Given an integer number n, return the difference between the product of its digits and the sum of its digits.
"""
1281. Subtract the Product and Sum of Digits of an Integer
Given an integer number n,
return the difference between the product of its digits and the sum of its digits.
Input: n = 234
Output: 15
Explanation:
Product of digits = 2 * 3 * 4 = 24
Sum of digits = 2 + 3 + 4 = 9
Result = 24 - 9 = 15
"""
n = 234
total = 0
mul = 1
while n != 0:
number = n % 10
total += number
mul *= number
n /= 10
n = int(n) # or not, it became like 2.34e-314 so loop won't stop
print(mul, "-", total, "=", mul - total)