10 examples of 'sum of digits of a number in python' in Python

Every line of 'sum of digits of a number in 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
45def sum_digits(num):
46 return sum(map(int, list(str(num))))
30def is_even_sum_of_digits(number):
31 lista = list(str(number))
32 lista = map(int, lista)
33 sum = reduce(operator.add, lista)
34
35 if sum % 2 == 0:
36 return True
37 return False
221def digit_count(x):
222 return sum(c.isdigit() for c in x)
48def calc_check_digit(number):
49 """Calculate the check digit. The number passed should not have the
50 check digit included."""
51 weights = (21, 19, 17, 13, 11, 9, 7, 3, 1)
52 return str(sum(w * int(n) for w, n in zip(weights, number)) % 10)
56def calc_check_digit(number):
57 """Calculate the check digits for the number."""
58 return str(sum(int(n) * (7 - i) for i, n in enumerate(number[:6])) % 10)
54def calc_check_digit(number):
55 """Calculate the check digit for personal codes. The number passed
56 should not have the check digit included."""
57 # note that this algorithm has not been confirmed by an independent source
58 weights = (2, 7, 9, 1, 4, 6, 3, 5, 8, 2, 7, 9)
59 check = sum(w * int(n) for w, n in zip(weights, number)) % 11
60 return '1' if check == 10 else str(check)
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]
24def digits_of(n):
25 return [int(d) for d in str(n)]
110def calc_check_digit(number):
111 """Calculate the extra digit that should be appended to the number to
112 make it a valid number."""
113 return str(_multiplication_table[checksum(str(number) + '0')].index(0))
71def calc_check_digit(number):
72 """Calculate the check digit. The number passed should have the check
73 digit included."""
74 checksum = (1 - 2 * int(number[:-1], 13)) % 11
75 return 'X' if checksum == 10 else str(checksum)

Related snippets