Project Euler problem #25
Varjinth subramaniyan
1 min read
#python program with test cases to find the index of 1000 digits fibonacci number
import unittest
def fib_index(n):
if type(n)!=int:
return 'Type error'
if n<1 :
return None
count=2
length=1
a,b=1,1
while length!=n:
c=a+b
a=b
b=c
count+=1
length=len(str(b))
return count
print(fib_index(1000))
class test_cases(unittest.TestCase):
def test_fib_index(self):
self.assertEqual(fib_index(-10),None)
self.assertEqual(fib_index('456'), 'Type error')
self.assertEqual(fib_index(3),12)
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