Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Digits Multiplication (solutions #2): using prod() from math solution in Clear category for Digits Multiplication by danila.s
"""
SOLUTIONS #1
from functools import reduce
def checkio(number: int) -> int:
# map(int, str(number)) - the number is divided on per digits
# filter() - we delete all zero
# reduce() - we multiply all digit
return reduce(lambda x, i: x * i, filter(None, map(int, str(number))))
"""
# SOLUTIONS #2
from math import prod
def checkio(number: int) -> int:
return prod(int(i) for i in str(number) if int(i))
if __name__ == '__main__':
print('Example:')
print(checkio(123405))
# These "asserts" using only for self-checking and not necessary for auto-testing
assert checkio(123405) == 120
assert checkio(999) == 729
assert checkio(1000) == 1
assert checkio(1111) == 1
print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")
March 10, 2021