Project Euler Problem#29
Varjinth subramaniyan
1 min read
#python program to find the no. of distinct terms are in the a power b sequence
import unittest
def distinct_power(num):
if type(num)!=int or num<2:
return None
list1=[]
for a in range(2,num+1):
for b in range(2,num+1):
if a**b not in list1:
list1.append(a**b)
return len(list1)
print(distinct_power(100))
class TestCases(unittest.TestCase):
def test_distinct_power(self):
self.assertEqual(distinct_power(-5),None)
self.assertEqual(distinct_power(5),15)
self.assertEqual(distinct_power("5"),None)
if __name__ == "__main__":
unittest.main()
0
Subscribe to my newsletter
Read articles from Varjinth subramaniyan directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by