Ejemplo n.º 1
0
def test_fact_big():
    assert fact.fact(33550336) == [
        1,
        2,
        4,
        8,
        16,
        32,
        64,
        128,
        256,
        512,
        1024,
        2048,
        4096,
        8191,
        16382,
        32764,
        65528,
        131056,
        262112,
        524224,
        1048448,
        2096896,
        4193792,
        8387584,
        16775168,
        33550336
    ]
Ejemplo n.º 2
0
def sin_calc(x, k=10):
    x = x % math.pi  # make the angle between 0 and pi
    sinx = 0
    for l, i in enumerate(range(1, k, 2)):
        temp = (((-1)**l) * (x**i)) / fact.fact(i)
        #print(temp)
        sinx += temp
    return sinx
Ejemplo n.º 3
0
def classify(number):
    if number < 1:
        raise ValueError('Must be > 0')
    if not isinstance(number, int):
        raise ValueError('Must be natural number')

    aliquot = sum(fact.fact(number)[:-1])
    if aliquot == number:
        return 'perfect'
    if aliquot > number:
        return 'abundant'
    if aliquot < number:
        return 'deficient'
Ejemplo n.º 4
0
import fact

print("__name__",fact.__name__)

print(fact.fact(15))
Ejemplo n.º 5
0
 def setUp(self):
     super(TestFact, self).setUp()
     self.fact_obj = fact.fact(self.bot)
Ejemplo n.º 6
0
def fact(n):
    return 1 if n == 1 else n * fact(n - 1)


if (__name__ == '__main__'):
    import sys
    if len(sys.argv) > 1:
        print(fact(int(sys.argv[1])))

from fact import fact
fact(6)
Ejemplo n.º 7
0
 def test_zero(self):
     r=fact.fact(0)
     self.assertEqual(r, factorial(0))
Ejemplo n.º 8
0
 def test_negative_number(self):
     '''Negative x'''
     r = fact.fact(-1)
     self.assertEqual(r, factorial(-1))
Ejemplo n.º 9
0
def sumbit():
    resp = request.get_json()
    res = str(fact.fact(resp['n']))
    resp = json.dumps({'res': res})
    print(resp)
    return resp
Ejemplo n.º 10
0
def test_fact_6():
    assert fact.fact(6) == [1, 2, 3, 6]
Ejemplo n.º 11
0
def test_fact_5():
    assert fact.fact(5) == [1, 5]
Ejemplo n.º 12
0
def test_fact_4():
    assert fact.fact(4) == [1, 2, 4]
Ejemplo n.º 13
0
def test_fact_3():
    assert fact.fact(3) == [1, 3]
Ejemplo n.º 14
0
def test_fact_2():
    assert fact.fact(2) == [1, 2]
Ejemplo n.º 15
0
def test_fact_1():
    assert fact.fact(1) == [1]
Ejemplo n.º 16
0
def fact(n):
    return 1 if n == 1 else n * fact(n - 1)
Ejemplo n.º 17
0
# Program to check whether no. is palindrome or not
number = '122'
number1 = number[::-1]
if number1 == number:
    print('palindrome')
else:
    print('is not palindrome')
print('-----------------------------------------------')

# Program to get the factorial using library function
num = 5
if num == 1:
    print(num)
else:
    fact_num = num * fact(num - 1)
    print(fact_num)
print('-----------------------------------------------')

# Program to check the no is armstrong number
num = int(input('enter the number'))
s = 0
temp = num
while temp > 0:
    c = temp % 10
    s += c**3
    temp //= 10
if num == s:
    print('armstrong')
else:
    print('not armstrong')
Ejemplo n.º 18
0
def test_fact_12():
    assert fact.fact(12) == [1, 2, 3, 4, 6, 12]
Ejemplo n.º 19
0
    backward_sum = 0
    for i in reversed(range(1, 10000)):
        backward_sum = backward_sum + (1 / (i * i * i * i))
    print("Backward Approx: " + str(backward_sum))
    print("Relative Accuracy: " + str((backward_sum / actual) * 100) + "%\n")

    #Problem 3
    print(
        "Problem 3: Estimate e^(-5) using series expansion and inverted series expansion"
    )
    actual = 6.737947 * (10**(-3))
    print("Actual : " + str(actual))
    num_terms = 20
    series_approx = 0
    for i in range(num_terms):
        series_approx = series_approx + ((-1)**(i)) * (((5)**(i)) / fact(i))
    print("Series Approx: " + str(series_approx))
    print("Relative Accuracy: " + str((series_approx / actual) * 100) + "%")
    inv_series_approx = 0
    for i in range(num_terms):
        inv_series_approx = inv_series_approx + (((5)**(i)) / fact(i))
    inv_series_approx = inv_series_approx**(-1)
    print("Inverted Series Approx: " + str(inv_series_approx))
    print("Relative Accuracy: " + str((inv_series_approx / actual) * 100) +
          "%\n")

    #Problem 4
    print(
        "Problem 4: Add terms to the approximation of cos(pi/3) until error falls beyond two sigfigs."
    )
    sig_bits = 2
Ejemplo n.º 20
0
def test_fact_36():
    assert fact.fact(36) == [1, 2, 3, 4, 6, 9, 12, 18, 36]
Ejemplo n.º 21
0
from fact import fact

print(fact(5))
Ejemplo n.º 22
0
def test_fact_0():
    assert fact.fact(0) == []
Ejemplo n.º 23
0
 def test_positive_number(self):
     '''Positive x'''
     r = fact.fact(10)
     self.assertEqual(r, factorial(10))
Ejemplo n.º 24
0
s = "local s"
print("s: ", s)
from mod import s
print("s: ", s)
from mod import s as alt_s
print("alt_s: ", alt_s)

import mod as alt_mod
print("alt_mod.s, ", alt_mod.s)

print("dir(): ", dir())
print("dir(mod): ", dir(mod))

from fact import fact
print("fact(6): ", fact(6))

print("<<import mod again (no additional output)")
import mod
import mod
print("import mod again (no additional output)>>")

print("<<import mod again (with reload)")
import importlib
importlib.reload(mod)
print("import mod again (with reload)>>")

print("pkg sample")
import pkg.mod1, pkg.mod2
# import pkg
pkg.mod1.foo()
Ejemplo n.º 25
0
 def test_one(self):
     r=fact.fact(1)
     self.assertEqual(r, factorial(1))
Ejemplo n.º 26
0
from fact import fact

fact(6)
print(fact)