def test_Fibonacci(): start = time.clock() for i in range(33): a = Fibonacci.Fibonacci(i) b = Fibonacci.Fibonacci(i + 1) c = Fibonacci.Fibonacci(i + 2) assert (a + b == c) elapsed = 1000 * (time.clock() - start) print('Time elapsed %.4f milliseconds' % elapsed) print("***PASSED ALL TESTS***")
def fibonacci_test(): fib = Fibonacci() # ITERATIF 35 begin = time.time() fib.iteratif_lineair(35) end = time.time() print("Temps iteratif pour 35 éléments: %d s" % (end - begin)) # RECURSIF 35 begin = time.time() fib.recursif(35) end = time.time() print("Temps récursif pour 35 éléments: %d s" % (end - begin)) # SUPER_ITERATIF 35 begin = time.time() fib.iteratif_super(35) end = time.time() print("Temps itératif super linéaire pour 35 éléments: %d s" % (end - begin)) # ITERATIF 100000 begin = time.time() fib.iteratif_lineair(100000) end = time.time() print("Temps iteratif pour 100000 éléments: %d s" % (end - begin)) # SUPER_ITERATIF 100000 begin = time.time() fib.iteratif_super(100000) end = time.time() print("Temps itératif superlinéaire pour 100000 éléments: %d s" % (end - begin))
def EvenFibonacciNumbers(UpTo=4000000): return sum([i for i in Fibonacci(1, 2, UpTo) if i % 2 == 0])
n_selection = input("Please input the value of n: ") if (int(n_selection) > 20): print("Error: Please input a value less than or equal to 20") else: veracity = True veracity = False while (not veracity): if (int(user_selection) == 1): print(Power.powerOfTwo(int(n_selection))) veracity = True elif (int(user_selection) == 2): veracity = True print(Factorial.factorial(int(n_selection))) elif (int(user_selection) == 3): print(Fibonacci.Fibonacci(int(n_selection))) veracity = True else: print("Invalid input please try again.\n") do_repeat = input("Would you like to try again(y/n)? ") if (do_repeat == "yes" or do_repeat == "y" or do_repeat == "Y" or do_repeat == "Yes"): repeat = True else: repeat = False
import math import Brent import dichotomy import function import GoldenRation import Fibonacci import Parabol import array import numpy import matplotlib.pyplot as plt import scipy as scipy epsilon = 0.1 a = 6 b = 10 # print('Дихтомия') # dichotomy.dichotomy(epsilon, a, b) # print('Золотое сечение') # GoldenRation.goldenRatio(epsilon, a, b) print('Фибоначи') Fibonacci.Fibonacci(epsilon, a, b) # print('метод Парабол') # print(Parabol.parabola(a, 7, b, epsilon)) # print('Брент') # print(Brent.Brent(epsilon, a, b))
def test_Fibonacci2(self): self.assertEqual(Fibonacci(6), 8)
def test_Fibonacci1(self): self.assertEqual(Fibonacci(5), 5)
def setUp(self): self.fibonacci = Fibonacci.Fibonacci()
def test_challenge4fibonacci(self): print(Fibonacci(9)) print(ConvertToString(103123))
def stack(l1,n): if n==1: i=int(input("ENTER THE ELEMENT TO BE PUSHED INTO THE STACK:")) l1.append(i) elif n==2: print("ELEMENT POPPED OUT IS ",l1.pop() elif n==3: print("ELEMENT AT TOP OF STACK IS ",l1[-1] elif n==4: print("ELEMENTS OF STACK ARE:") for i in range(0,len(l1)): print(l1[i],end=" ") #MODULE IMPORTED IN PROGRAM: import teststack a=1 l1=[] while a==1: print("\n1:PUSH 2:POP 3:PEEP 4:DISPLAY") n=int(input("ENTER WHICH STACK OPERATION TO PERFORM:")) if n<=4: teststack.stack(l1,n) a=1 a=int(input("\nPRESS 1 TO CONTINUE 0 TO EXIT:")) OUTPUT: 1:PUSH 2:POP 3:PEEP 4:DISPLAY ENTER WHICH STACK OPERATION TO PERFORM:1 ENTER THE ELEMENT TO BE PUSHED INTO THE STACK:5 PRESS 1 TO CONTINUE 0 TO EXIT:1 1:PUSH 2:POP 3:PEEP 4:DISPLAY ENTER WHICH STACK OPERATION TO PERFORM:1 ENTER THE ELEMENT TO BE PUSHED INTO THE STACK:7 PRESS 1 TO CONTINUE 0 TO EXIT:1 1:PUSH 2:POP 3:PEEP 4:DISPLAY ENTER WHICH STACK OPERATION TO PERFORM:1 ENTER THE ELEMENT TO BE PUSHED INTO THE STACK:1 PRESS 1 TO CONTINUE 0 TO EXIT:1 1:PUSH 2:POP 3:PEEP 4:DISPLAY ENTER WHICH STACK OPERATION TO PERFORM:4 ELEMENTS OF STACK ARE: 5 7 1 PRESS 1 TO CONTINUE 0 TO EXIT:1 1:PUSH 2:POP 3:PEEP 4:DISPLAY ENTER WHICH STACK OPERATION TO PERFORM:3 ELEMENT AT TOP OF STACK IS 1 PRESS 1 TO CONTINUE 0 TO EXIT:1 1:PUSH 2:POP 3:PEEP 4:DISPLAY ENTER WHICH STACK OPERATION TO PERFORM:2 ELEMENT POPPED OUT IS 1 PRESS 1 TO CONTINUE 0 TO EXIT:1 1:PUSH 2:POP 3:PEEP 4:DISPLAY ENTER WHICH STACK OPERATION TO PERFORM:4 ELEMENTS OF STACK ARE: 5 7 PRESS 1 TO CONTINUE 0 TO EXIT:0 PROGRAM FOR CREATING PACKAGES: class Fibonacci: def __init__(self,n): self.n=n def fibo(self,n): if n==1 or n==2: return 1 else: return((self.fibo(n-1)+self.fibo(n-2))) def printfibo(self,n): for i in range(1,(n+1)): print(self.fibo(i)) class Lucas: def __init__(self,n): self.n=n def luca(self,n) : if (n == 0) : return 2 if (n == 1) : return 1 return self.luca(n - 1) + self.luca(n - 2) def printluca(self,n): for i in range(1,(n+1)): print(self.luca(i)) PACKAGE IMPORTED IN OTHER PROGRAM: from series import Fibonacci from series import Lucas op=1 while(op!=3): print("MENU\n1.FIBONACCI 2.LUCAS 3.EXIT") op=int(input("ENTER YOUR OPTION:")) if (op==1): n=int(input("ENTER NUMBER OF TERMS: ")) obj=Fibonacci(n) obj.printfibo(n) elif (op==2): n=int(input("ENTER NUMBER OF TERMS: ")) obj=Lucas(n) obj.printluca(n) else: break OUTPUT: MENU 1.FIBONACCI 2.LUCAS 3.EXIT ENTER YOUR OPTION:1 ENTER NUMBER OF TERMS: 5 1 1 2 3 5 MENU 1.FIBONACCI 2.LUCAS 3.EXIT ENTER YOUR OPTION:2 ENTER NUMBER OF TERMS: 5 1 3 4 7 11 MENU 1.FIBONACCI 2.LUCAS 3.EXIT ENTER YPUR OPTION:3