Hi @aliibrahim23 ,
In your original code, you had this outside the function definition ...
answer = 0
Therefore, no matter how many times you call the
digit_sum function within your program, that line only executes once. That is a problem, because you need to have
answer initialized to a value of
0 each time you begin to add up the values of the digits in a number. If you place the initialization mechanism inside the function, then it can execute each time the function is called.
Whenever possible, design functions to be self-contained units. Occasionally, there is a good reason to have a function use a global variable. Only use global variables when you have a good reason to do so, otherwise you are introducing unnecessary complexity to your program, and increasing the likelihood of bugs.