Recursive Digit Sum

  • + 1 comment

    Instead of x if x else 9 you can just do x or 9

    • + 2 comments

      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'?

      • + 0 comments

        it means: if x>0 then return x because if x=0 and 0==false then return 9

      • + 0 comments

        https://en.wikipedia.org/wiki/Modular_arithmetic