취미생활/CheckIO
[checkIO]Element 04.Digits Multiplication
우주먼지의하루
2020. 2. 26. 10:45
728x90
You are given a positive integer. Your function should calculate the product of the digits excluding any zeroes.
For example: The number given is 123405. The result will be 1*2*3*4*5=120 (don't forget to exclude zeroes).
Input: A positive integer.
Output: The product of the digits as an integer.
Example:
checkio(123405) == 120
checkio(999) == 729
checkio(1000) == 1
checkio(1111) == 1
* 0을 빼고 각 자리 숫자를 곱한다
- 풀이
def checkio(number: int) -> int:
number_string = str(number)
result = 1
for i in number_string:
if i !="0":
result = result * int(i)
return result
반응형