brewersfan1976

digits_product.py

Sep 5th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | None | 0 0
  1. def digitsProduct(product):
  2.     x = 0
  3.     y = 0
  4.     amount = 1
  5.    
  6.     if product == 0:
  7.        return 10
  8.  
  9.     while (x <= 10000):
  10.           string = str(x)
  11.           string_length = len(string)
  12.        
  13.           while (y < string_length):
  14.                 amount = amount * int(string[y])
  15.                 y = y + 1
  16.                
  17.           if amount == product:
  18.              return int(string)
  19.          
  20.           x = x + 1
  21.           y = 0
  22.           amount = 1
  23.    
  24.     return -1
Advertisement
Add Comment
Please, Sign In to add comment