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.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/ab5019e0-e66f-432f-b61d-50770e5f7736/Screen_Shot_2021-04-01_at_12.05.29_PM.png

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/b7a0bd2b-597a-4863-a56b-5d8d40ee37b9/Untitled.png

"""
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)

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/21ab911b-add2-41b8-8f8b-9158ad49dee7/Screen_Shot_2021-04-01_at_12.17.31_PM.png