Well unfortunately there are a few problems, I will try to go over them the best that I can.
First off, having an
else statement in the wild by itself will not allow the code to run correctly since there is no
if statement before it.
Second, the reason why you are getting that error is because you never reference the variable
sum_number before the return statement. The reason for this is the fact that if a number is entered that is lower than 10, the
while loop will never be entered and therefore the function will try to return a variable that has not been instantiated yet resulting in the error that you see.
Lastly, Taking a look at the problem you are trying to solve, while your thinking is on the right path, the problem is really wanting you to take
n and split it up into all of its digit counterparts and then add them together. For example, if
n = 1234, you would want to split that number up and then add the digits together so you would end up with
1 + 2 + 3 + 4 = 10. Do you see the difference from what you are currently trying to do?
If you need more help or need me to explain anything better, let me know.