I am trying to solve the challenge enclosed in the Hint. It asks to use % or // within a pattern to isolate all of the digits given in a number, and then to add them to a total. Here is the link:
I tried to use floor divide to isolate each digit by dividing it by 10 * 3, then, * 2, then * 1, as appropriate. Here is my attempt:
numbers =  def digit_sum(n): s = str(n) l = len(s) if n > 0: for d in range(l): number = int(n // (10 * (l - (int(s[d])))) print number numbers.append(number) print sum(numbers)
The error reads:
Did you create a function called digit_sum? Your code threw a "global name 'digit_sum' is not defined" error.
File "python", line 16
SyntaxError: invalid syntax
If I delete "print number", the same occurs for the following line.
Any advice helps. Also, if you have recommendations of how to go about the same task using % instead.
Thanks mtf for all your suggestions!