Function to sum a multi digit number until a single digit is returned

I need help with with writing a python script to sum a multi digit number until a single digit is left. So any number equal to 10 or greater.

The program will accept 10 for instance and return 1.

Numbers 1 - 9 should return as an error and 0 should return as 0. Entries that are not int should return an error too.

I have written multiple versions of this but I can not seem to get it to work the way I want it to.

Here is some code I am working with:

  def SumDig(n):
    n = []
   if(not isinstance(n, int)) or (n <= 9) or (n >= 1):
      return ("Error")
   elif(n >= 10):
      return (n - 1) % 9 + 1;
   return SumDig(n)


from Recent Questions - Stack Overflow https://ift.tt/2UTR7P7
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation