Numbers
Data Types
Integers
Algorithms
Logic
digits = lambda n : len(str(abs(n)))
digits = lambda n : len(str(n))- digits = lambda n : len(str(abs(n)))
test.describe("Powers of 10") test.assert_equals(digits(0), 1) n = 1 for i in range(1,21): n *= 10 test.assert_equals(digits(n), i+1) import sys test.assert_equals(digits(sys.maxsize), 19) test.describe("Powers of 10 minus 1") n = 1 for i in range(1,21): n *= 10 test.assert_equals(digits(n-1), i) test.describe("Powers of 10 half") n = 1 for i in range(1, 21): n *= 10 test.assert_equals(digits(n // 2), i) test.describe("Negative powers of 10") n = 1 for i in range(1, 21): n *= 10 test.assert_equals(digits(-n), i+1)
- test.describe("Powers of 10")
- test.assert_equals(digits(0), 1)
- n = 1
- for i in range(1,21):
- n *= 10
- test.assert_equals(digits(n), i+1)
- import sys
- test.assert_equals(digits(sys.maxsize), 19)
- test.describe("Powers of 10 minus 1")
- n = 1
- for i in range(1,21):
- n *= 10
- test.assert_equals(digits(n-1), i)
- test.describe("Powers of 10 half")
- n = 1
- for i in range(1, 21):
- n *= 10
- test.assert_equals(digits(n // 2), i)
- test.describe("Negative powers of 10")
- n = 1
- for i in range(1, 21):
- n *= 10
- test.assert_equals(digits(-n), i+1)