def test_1(self):
     if Factorial.factorial(1) == 1:
         FactorialTest.f.write("1,,1\n")
     else:
         FactorialTest.f.write(
             "0,Unsuccessful normal factorial generation,1\n")
     self.assertEqual(Factorial.factorial(1), 1)
 def test_4(self):
     if Factorial.factorial(4) == 24:
         FactorialTest.f.write("1,,4\n")
     else:
         FactorialTest.f.write(
             "0,Unsuccessful normal factorial generation,4\n")
     self.assertEqual(Factorial.factorial(4), 24)
示例#3
0
    def testFactorial(self):
        print("\n%%%%%%% Testing Factorial")
        expectedResult = 1307674368000
        result = Factorial.factorial(15)
        print("factorial(15)=" + str(result))
        self.assertEqual(result, expectedResult, msg="factorial(15)")

        expectedResult = 5040
        result = Factorial.factorial(7)
        print("factorial(7)=" + str(result))
        self.assertEqual(result, expectedResult, msg="factorial(7)")

        expectedResult = 8841761993739701954543616000000
        result = Factorial.factorial(29)
        print("factorial(46)=" + str(result))
        self.assertEqual(result, expectedResult, msg="factorial(46)")
示例#4
0
import Factorial

n = input("n?")
f = Factorial.factorial(n)
示例#5
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
示例#6
0
def combination(n,r):
    return(Factorial.factorial(n) / (Factorial.factorial(r) * Factorial.factorial(n-r)))
示例#7
0
# -*- coding: utf-8 -*-
"""
Created on Tue Oct 16 10:27:07 2018

@author: LZC
"""

import Factorial as Fa
# import Fun_0.Fibonacci as Fi
from Fun_0 import Fibonacci as Fi
a = 0
F1 = Fa.facto_L(a)
print(a, '的阶乘为:', F1)
a = 5
F2 = Fa.facto_L(a)
print(a, '的阶乘为:', F2)

c = 60
F3 = Fi.Fibo(c)
print(c, '以内的费波纳希数列:', F3[:-1])
 def test_0(self):
     if Factorial.factorial(0) == 1:
         FactorialTest.f.write("1,,5\n")
     else:
         FactorialTest.f.write("0,Zero factorial generation improper,5\n")
     self.assertEqual(Factorial.factorial(0), 1)
 def test_3(self):
     if Factorial.factorial(3) == 3:
         FactorialTest.f.write("1,,3\n")
     else:
         FactorialTest.f.write("0,3 factorial failue,3\n")
     self.assertEqual(Factorial.factorial(3), 3)
示例#10
0
 def test_4(self):
   if Factorial.factorial(4)==24:
     FactorialTest.f.write("1,,4\n")
   else:
     FactorialTest.f.write("0,Unsuccessful normal factorial generation,4\n")
   self.assertEqual(Factorial.factorial(4),24)
示例#11
0
 def test_3(self):
   if Factorial.factorial(3)==3:
     FactorialTest.f.write("1,,3\n")
   else:
     FactorialTest.f.write("0,3 factorial failue,3\n")
   self.assertEqual(Factorial.factorial(3),3)
示例#12
0
 def test_2(self):
   if Factorial.factorial(2)==2:
     FactorialTest.f.write("1,,2\n")
   else:
     FactorialTest.f.write("0,Zero factorial generation improper,2\n")
   self.assertEqual(Factorial.factorial(2),2)
示例#13
0
 def test_1(self):
   if Factorial.factorial(1)==1:
     FactorialTest.f.write("1,,1\n")
   else:
     FactorialTest.f.write("0,Unsuccessful normal factorial generation,1\n")
   self.assertEqual(Factorial.factorial(1),1)
示例#14
0
import Factorial, importOraginal

importOraginal.test().show()
print(importOraginal.test().show())
print(Factorial.Factorial().result(12))
示例#15
0
import Factorial

Factorial.factorial(3)
示例#16
0
#!/usr/bin/env python

import Factorial

if __name__ == '__main__':
    f = Factorial.Factorial()
    g = Factorial.Factorial(5)

    result_1 = f.compute()
    result_2 = g.compute()

    print "Factorial value 1: {}".format(result_1)
    print "Factorial value 2: {}".format(result_2)
 def test_2(self):
     if Factorial.factorial(2) == 2:
         FactorialTest.f.write("1,,2\n")
     else:
         FactorialTest.f.write("0,Zero factorial generation improper,2\n")
     self.assertEqual(Factorial.factorial(2), 2)
示例#18
0
 def test_0(self):
   if Factorial.factorial(0)==1:
     FactorialTest.f.write("1,,5\n")
   else:
     FactorialTest.f.write("0,Zero factorial generation improper,5\n")
   self.assertEqual(Factorial.factorial(0),1)
示例#19
0
 def test_7(self):
   if Factorial.factorial(7)==5040:
     FactorialTest.f.write("1,,6\n")
   else:
     FactorialTest.f.write("0,Large factorial failue,6\n")
   self.assertEqual(Factorial.factorial(7),5040)
 def test_recurrsive_factorial(self):
     #Looping through some relatively low numbers to test sequential factorial
     inputs = [3,8,4,10,-1,1,0]
     results = [6,40320,24,3628800,"FAILED inappropriate input value",1,1]
     for x, my_inp in enumerate(inputs):
         self.assertEqual(Factorial.recurrsive_factorial(inputs[x]),results[x])
 def test_7(self):
     if Factorial.factorial(7) == 5040:
         FactorialTest.f.write("1,,6\n")
     else:
         FactorialTest.f.write("0,Large factorial failue,6\n")
     self.assertEqual(Factorial.factorial(7), 5040)
示例#22
0
def permutation(n, r):
    return (Factorial.factorial(n) / (Factorial.factorial(n - r)))