취미생활/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

 

반응형

'취미생활 > CheckIO' 카테고리의 다른 글

[checkIO]Element 06.Fizz Buzz  (0) 2020.03.03
[checkIO]Element 05.Secret Message  (0) 2020.03.01
[checkIO]Element 03.Index Power  (0) 2020.02.24
[checkIO]Element 02.Easy Unpack  (0) 2020.02.22
[checkIO]Element 01.Say Hi  (0) 2020.02.21