Stuck


#1

def digit_sum(int(n)):
return xx=str(int(n))
for char in xx:
return int(char)

INSTRUCTIONS:
.
Write a function called digit_sum that takes a positive integer n as input and returns the sum of all that number’s digits. For example: digit_sum(1234) should return 10 which is 1 + 2 + 3 + 4. (Assume that the number you are given will always be positive.)

ERROR TYPE:
File “python”, line 1
def digit_sum(int(n)):
^
SyntaxError: invalid syntax


#2

here:

def digit_sum(int(n)):

you can’t convert a function parameter (n in this case) to a integer


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.