odz #1867(2007/08/05 09:57 GMT) [ Python ] Rating1/1=1.00
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
#!/usr/bin/env python # -*- coding: utf-8 -*- import sys def digits(n): """ returns count of digits and order of most siginificant digit. >>> digits(2469) (4, 1000) >>> digits(600) (3, 100) >>> digits(1) (1, 1) >>> digits(0) (1, 1) >>> digits(-100) (3, 100) """ if n < 0: n = -n s = str(n) return (len(s), 10 ** (len(s) - 1)) def _test(): import doctest doctest.testmod() if __name__ == '__main__': _test()
Rating1/1=1.00-0+
[ reply ]
odz #1867() [ Python ] Rating1/1=1.00
Rating1/1=1.00-0+
[ reply ]