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 ]
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
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'
import fact print("__name__",fact.__name__) print(fact.fact(15))
def setUp(self): super(TestFact, self).setUp() self.fact_obj = fact.fact(self.bot)
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)
def test_zero(self): r=fact.fact(0) self.assertEqual(r, factorial(0))
def test_negative_number(self): '''Negative x''' r = fact.fact(-1) self.assertEqual(r, factorial(-1))
def sumbit(): resp = request.get_json() res = str(fact.fact(resp['n'])) resp = json.dumps({'res': res}) print(resp) return resp
def test_fact_6(): assert fact.fact(6) == [1, 2, 3, 6]
def test_fact_5(): assert fact.fact(5) == [1, 5]
def test_fact_4(): assert fact.fact(4) == [1, 2, 4]
def test_fact_3(): assert fact.fact(3) == [1, 3]
def test_fact_2(): assert fact.fact(2) == [1, 2]
def test_fact_1(): assert fact.fact(1) == [1]
def fact(n): return 1 if n == 1 else n * fact(n - 1)
# 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')
def test_fact_12(): assert fact.fact(12) == [1, 2, 3, 4, 6, 12]
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
def test_fact_36(): assert fact.fact(36) == [1, 2, 3, 4, 6, 9, 12, 18, 36]
from fact import fact print(fact(5))
def test_fact_0(): assert fact.fact(0) == []
def test_positive_number(self): '''Positive x''' r = fact.fact(10) self.assertEqual(r, factorial(10))
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()
def test_one(self): r=fact.fact(1) self.assertEqual(r, factorial(1))
from fact import fact fact(6) print(fact)