Sticky Quersumme berechnen

    This site uses cookies. By continuing to browse this site, you are agreeing to our use of cookies. More details

    • Quersumme berechnen



      Mir war mal spontan danach. Also hier eine mögliche Hilfsfunktion, um die Quersumme einer Zahl rekursiv zu ermitteln.

      Python Source Code

      1. def qSum(value):
      2. if value <> 0:
      3. return int(str(value)[-1]) + qSum(value/10)
      4. else:
      5. return 0
      6. def main():
      7. print("\t\t__//--Awesome QSum--\\\\__\n\n")
      8. print("qSum(6450) = %d" % qSum(6450))
      9. print("qSum(489276895) = %d" % qSum(489276895))
      10. print("qSum(111) = %d" % qSum(111))
      11. print("qSum(22339911557766998800) = %d" % qSum(22339911557766998800))
      12. print("\n _____________")
      13. print("/ AWESOME \")
      14. print(" -------------\n")
      15. if __name__ == '__main__':
      16. main()
      Display All