Пример #1
0
def main():
    # Gets user input from the command line and converts it to an int
    # Needs error checking here
    n = int(raw_input("Please chose which Fibonacci Number you would like to see: "))

    # Fibo function called and printed here
    print fibonacci.fibo(n)
Пример #2
0
def fibo():
    if request.method == 'GET':
        lg = request.args.get('lg')
        add = "_uk" if lg == "uk" else ""
        where = 'fibonacci'
        path = 'pages/placeholder.' + where + add + '.html'
        return render_template(path,
                               result=None,
                               query="",
                               errors=None,
                               lg=lg if lg else "en")
    data = request.form.get('fibo')
    lg = request.form.get('lg')
    add = "_uk" if lg == "uk" else ""
    lg_val = 1 if lg == "uk" else 0
    where = 'fibonacci'
    path = 'pages/placeholder.' + where + add + '.html'
    if data == "" or data is None:
        return render_template(path,
                               result=None,
                               query="",
                               errors=[
                                   "  Expression can`t be empty",
                                   "  Вираз не може бути порожнім"
                               ][lg_val],
                               lg=lg if lg else "en")
    else:
        res, e = fibonacci.fibo(data, lg_val)
        return render_template(path,
                               result=res,
                               query=data.replace(" ", ""),
                               errors=e,
                               lg=lg if lg else "en")
Пример #3
0
def getFibo():
    if 'number' in request.args:
        number = int(request.args['number'])
    else:
        return "Input incorrecto"

    return str(fibo(number))
Пример #4
0
 def test_fibonacci(self):
     a = [random.randint(6, 20) for _ in range(5)]
     ans = _("The {}th fibonacci number is {} and you returned {}.")
     for i in range(len(a)):
         stu_ans = fibonacci.fibo(a[i])
         corr_ans = corr.fibonacci(a[i])
         self.assertEqual(corr_ans, stu_ans, ans.format(a[i], corr_ans, stu_ans))
Пример #5
0
def fibo():
    lg = request.args.get('lg')
    path = compose_path("fibonacci", lg)
    if request.method == 'GET':
        return render_template(path,
                               result=None,
                               query="",
                               errors=None,
                               lg=lg if lg else "en")
    data = request.form.get('fibo')
    lg_val = 1 if lg == "uk" else 0
    if data == "" or data is None:
        return render_template(path,
                               result=None,
                               query="",
                               errors=[
                                   "  Expression can`t be empty",
                                   "  Вираз не може бути порожнім"
                               ][lg_val],
                               lg=lg if lg else "en")
    else:
        res, e = fibonacci.fibo(data, lg_val)
        return render_template(path,
                               result=res,
                               query=data.replace(" ", ""),
                               errors=e,
                               lg=lg if lg else "en")
Пример #6
0
 def test_negatives(self):
     a = [-(random.randint(1, 100)) for _ in range(5)]
     ans = _("There can not be a number in a negative place in a sequence, you should have returned None.")
     for i in range(len(a)):
         try:
             stu_ans = fibonacci.fibo(a[i])
             self.assertEqual(None, stu_ans, ans)
         except RecursionError:
             self.assertFalse(True, ans)
Пример #7
0
def CalculcarPanDigitalDoble():
    count = 2750 # la respuesta del problema es 329468
    while True:
        numeroEvaluar = str(fibonacci.fibo(count))
        panDigitalI = numeroEvaluar[:9]
        panDigitalD = numeroEvaluar[len(numeroEvaluar)-9:]
        if EsPanDigital(panDigitalI) and EsPanDigital(panDigitalD):
            return  numeroEvaluar
        else:
            count+=1
            print(count)
            continue   
 def generate_fibonacci(self, num):
     for i in range(num):
         self.temp += str(fibonacci.fibo(i))
Пример #9
0
import fibonacci
print fibonacci.fibo(100)
Пример #10
0
 def test_simple(self):
     for n, fib_n in (1, 1), (2, 1), (3, 2), (4, 3), (5, 5):
         with self.subTest(i=n):
             self.assertEqual(fibo(n), fib_n)
Пример #11
0
 def test_positive(self):
     self.assertEqual(fibo(10), 56)
Пример #12
0
 def test_one(self):
     ans = _("For 1 the fibonacci number is 1 and you returned {}.")
     stu_ans = fibonacci.fibo(1)
     self.assertEqual(1, stu_ans, ans.format(stu_ans))
Пример #13
0
def test_3():
    with pytest.raises(TypeError):
        fibonacci.fibo("three")
Пример #14
0
def test_2():
    assert fibonacci.fibo(3) == 2
Пример #15
0
def test_1():
    assert fibonacci.fibo(0) == 0
Пример #16
0
 def test4(self):
     with self.assertRaises(Exception):
         fibonacci.fibo(-3)
Пример #17
0
 def test3(self):
     with self.assertRaises(TypeError):
         fibonacci.fibo("three")
Пример #18
0
 def test2(self):
     self.assertEqual(fibonacci.fibo(3), 2)
Пример #19
0
def cached_fibo(n):
    return fibo(n)
Пример #20
0
 def setUp(self):
     a = random.randint(6, 30)
     ans = _("You did not use recursion in your algorithm.")
     fibonacci.fibo = Counter(fibonacci.fibo)
     stu_ans = fibonacci.fibo(a)
     self.assertNotEqual(1, fibonacci.fibo.counter, ans)
Пример #21
0
def test_4():
    with pytest.raises(Exception):
        fibonacci.fibo(-3)
Пример #22
0
 def test_zero(self):
     ans = _("For 0 the fibonacci number is 0 and you returned {}.")
     stu_ans = fibonacci.fibo(0)
     self.assertEqual(0, stu_ans, ans.format(stu_ans))
Пример #23
0
 def test1(self):
     self.assertEqual(fibonacci.fibo(0), 0)
Пример #24
0
 def test_fibo(self):
     for i in range(len(self.cases)):
         self.assertAlmostEqual(fibonacci.fibo(self.cases[i][0]),
                                self.cases[i][1])
Пример #25
0
 def test_fibonacci(self):
     self.assertEqual(fibonacci.fibo(5), [1, 1, 2, 3, 5])
     self.assertEqual(fibonacci.fibo(10),
                      [1, 1, 2, 3, 5, 8, 13, 21, 34, 55])
Пример #26
0
 def test_zero(self):
     self.assertEqual(fibo(0), 0)
Пример #27
0
 def test_fibo2(self):
     self.assertEqual(fibonacci.fibo(14), 377)
Пример #28
0
#!/usr/bin/python

# import the module

import fibonacci

print("fibonacci.fibo(x): ")
# Using the module name you can access the functions
fibonacci.fibo(50)
print("fibonacci.fibolist(80):", fibonacci.fibolist(80))

#imports all name except those beginning with an underscore (_)
print("fibonacci.__name__ : ", fibonacci.__name__ )


# import the module using from
from fibonacci import fibo, fibolist

print("fibo(50): ")
# using the module name you can access the functions
fibo(50)
print("fibolist(80) : ", fibolist(80))


# import all the modules using from
from fibonacci import *

print("fibo(50) :")
#using the module name you can access the functions
fibo(50)
print("fibolist(80) : ", fibolist(80))
Пример #29
0
from fibonacci import fibo
print fibo(100)
Пример #30
0
 def test_fibonacci(self):
     self.assertEqual(fibo(1), 1)
     self.assertEqual(fibo(2), 1)
     self.assertEqual(fibo(5), 5)
     self.assertEqual(fibo(18), 2584)
Пример #31
0
#!/usr/bin/python

# import the module
import fibonacci

if __name__ == "__main__":
    import sys
    fibonacci.fibo(int(sys.argv[1]))
Пример #32
0
 def test_fibo1(self):
     self.assertEqual(fibonacci.fibo(7), 13)
Пример #33
0
import fibonacci
print(fibonacci.fibo(45))
Пример #34
0
def test_fib(n, res):
    assert fibo(n) == res
#!/usr/bin/python

# import the module

import fibonacci

print("fibonacci.fibo(x): ")
# Using the module name you can access the functions
fibonacci.fibo(50)
print("fibonacci.fibolist(80):", fibonacci.fibolist(80))

#imports all name except those beginning with an underscore (_)
print("fibonacci.__name__ : ", fibonacci.__name__ )


# import the module using from
from fibonacci import fibo, fibolist

print("fibo(50): ")
# using the module name you can access the functions
fibo(50)
print("fibolist(80) : ", fibolist(80))


# import all the modules using from
from fibonacci import *

print("fibo(50) :")
#using the module name you can access the functions
fibo(50)
print("fibolist(80) : ", fibolist(80))