Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Program that returns number of digits in a given integer (either positive or negative)
- '''
- def ndigits(x):
- # Assume for the input 0 the output is 0
- if(x == 0):
- return 0
- if(abs(x) / 10 == 0):
- return 1
- else:
- return 1 + ndigits(x / 10)
- def ndigits(x):
- # Assume for the input 0 the output is 0
- if(x == 0):
- return 0
- else:
- return 1 + ndigits(abs(x) / 10)
- def ndigits(x):
- return ndigits_(0, abs(x))
- def ndigits_(s,x):
- if(x == 0):
- return s
- else:
- return ndigits(s+1, x / 10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement