Advertisement
davide1409

divisibile3

Jan 6th, 2020
402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.41 KB | None | 0 0
  1. def cifre(n):
  2. #@param n: int
  3. #@return list
  4.   r, m = n, []
  5.   while(r!=0):
  6.     m.append(r%10)
  7.     r = r/10
  8.   return m
  9.  
  10.  
  11. def divisibile3(n):
  12. #@param n: int
  13. #@return: bool
  14.   if n<10:
  15.     if n<3:
  16.       return False
  17.     elif n == 3 or n == 6 or n == 9:
  18.       return True
  19.     else:
  20.       return False
  21.  
  22.   else:
  23.     somma = 0
  24.     for i in cifre(n):
  25.       somma+=i
  26.     return divisibile3(somma)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement