We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Can someone provide explaination as to what "return(x if x else 9)" is doing? I understand it is returning the output, but I do not understand the logic of how because how does the proram know when to return '9' versus 'x'?
Recursive Digit Sum
You are viewing a single comment's thread. Return to all comments →
Instead of
x if x else 9
you can just dox or 9
Can someone provide explaination as to what "return(x if x else 9)" is doing? I understand it is returning the output, but I do not understand the logic of how because how does the proram know when to return '9' versus 'x'?
it means: if x>0 then return x because if x=0 and 0==false then return 9
https://en.wikipedia.org/wiki/Modular_arithmetic