blob: 6c51d189e2eef946c8b5c6c05525acaab85d3e17 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
#!/usr/bin/env python3
import math
def is_power_three(number):
''' Given a positive integer. Returns true if the given integer is a power
of three otherwise returns false.
>>> is_power_three(27)
True
>>> is_power_three(0)
True
>>> is_power_three(6)
False
'''
cr = round(math.pow(number, 1/3), 6)
return ((cr - int(cr)) == 0)
if __name__ == "__main__":
import doctest
doctest.testmod()
|