Advertisement
STANAANDREY

LSD3 4

Oct 14th, 2022
889
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. def prod(n):
  2.     if n == 0:
  3.         return 1
  4.  
  5.     return (n % 10) * prod(n // 10)
  6.  
  7. def nr_digits(n):
  8.     if n == 0:
  9.         return 1
  10.  
  11.     if n // 10 != 0:
  12.         return 1 + nr_digits(n // 10)
  13.     else:
  14.         return 1
  15.  
  16. def max_digit(n):
  17.     if n == 0:
  18.         return 0
  19.    
  20.     return max(n % 10, max_digit(n // 10))
  21.  
  22. def nr_even_digits(n):
  23.     if n == 0:
  24.         return 1
  25.  
  26.     if n // 10 != 0:
  27.         if ((n % 10) % 2) == 1:
  28.             return nr_even_digits(n // 10)
  29.         else:
  30.             return 1 + nr_even_digits(n // 10)
  31.     else:
  32.         if ((n % 10) % 2) == 1:
  33.             return 0
  34.         else:
  35.             return 1
  36.  
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement