Advertisement
makispaiktis

Break a number to its digits

Mar 15th, 2021 (edited)
712
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.31 KB | None | 0 0
  1. n = int(input("n = "))
  2. nInitial = n
  3. nDigits = 0
  4. for i in range(10):
  5.     if n / (10**i) < 1:
  6.         nDigits = i
  7.         break
  8. print("nDigits = " + str(nDigits))
  9. digits = list()
  10. for i in range(nDigits-1, -1, -1):
  11.     digit = n // (10**i)
  12.     n = n - digit * (10**i)
  13.     digits.append(digit)
  14. print(digits)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement