Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Ignore the zeros, you say! solution in Clear category for Digits Multiplication by tigercat2000
def checkio(number):
# Initialize return as None.
product = None
# Convert number into string and iterate over each character with a for..in loop.
for n in str(number):
# Convert the character back to an integer.
i = int(n)
# Set the product to the first number and continue if it hasn't been set already.
if product == None:
product = i
continue
# Ignore 0s.
if(i == 0):
continue
# Set the product equal to the product times the number.
product = product * i
# Return the product.
return product
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
assert checkio(123405) == 120
assert checkio(999) == 729
assert checkio(1000) == 1
assert checkio(1111) == 1
Nov. 5, 2016