3 examples of 'split number into digits python' in Python

Every line of 'split number into digits python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
143def split_decimal(value):
144 import decimal
145 decimal.getcontext().prec = 2
146 d = decimal.Decimal(value)
147 i = int(d)
148 return (i, d - i)
68def splitnum(self, value):
69 for elem in self.cards:
70 if elem > value:
71 continue
72
73 out = []
74 if value == 0:
75 div, mod = 1, 0
76 else:
77 div, mod = divmod(value, elem)
78
79 if div == 1:
80 out.append((self.cards[1], 1))
81 else:
82 if div == value: # The system tallies, eg Roman Numerals
83 return [(div * self.cards[elem], div*elem)]
84 out.append(self.splitnum(div))
85
86 out.append((self.cards[elem], elem))
87
88 if mod:
89 out.append(self.splitnum(mod))
90
91 return out
84def _check_digit(number):
85 """Calculate a single check digit on the provided part of the number."""
86 weights = (13, 15, 12, 5, 4, 17, 9, 21, 3, 7, 1)
87 s = sum(w * (int(n) if n.isdigit() else alphabet.find(n) + 1)
88 for w, n in zip(weights, number))
89 return 'MQWERTYUIOPASDFGHJKLBZX'[s % 23]

Related snippets