def __init__(self, matrix1, matrix2, result, vector):
     # self.newname = Parameter
     self.matrix1 = matrix1
     self.matrix2 = matrix2
     self.result = result
     self.vector = vector
     # create obj of utility class
     self.obj = UtilClass()
예제 #2
0
    def __init__(self):
        # 1 % womans have breaste cancer i.e P(A) = 0.01
        self.breast_cancer = 0.01
        # womans who doesnt have breast cancer i.e  1 - breast_cancer or (1- P(A))
        self.not_breast_cancer = 0.99

        #  Ninety percent of women who have breast cancer test positive i.e. P(B) = 0.9
        self.positive_breast_cancer = 0.9

        # Eight percent of women will have false positives i.e p(-B) = 0.008
        self.false_breast_cancer = 0.08

        self.obj1 = UtilClass()
class Child(Parent):
    # class constructor
    def __init__(self):
        # create obj of utility class
        self.obj = UtilClass()

    # display method to display original matrix and vector
    def display(self):
        print("Original Matrix1: ")
        for temp11 in self.matrix1:
            print(temp11)
        # print("__________________________________________")
        print("Original Matrix2: ")
        for temp11 in self.matrix2:
            print(temp11)
        # print("__________________________________________")
        print("Original Vector: ")
        print(self.vector1)
        # print("__________________________________________")

    # Vector and matrix multiplication
    def mat_addition(self):
        # Matrix addition
        value1 = self.obj.matrix_addtn(self.matrix1, self.matrix2, self.result)

        # following for loop show addition of two matrices
        for temp4 in value1:
            print(temp4)
class Child2(Parent):
    # class constructor
    def __init__(self):
        self.obj = UtilClass()

    # matrix1 and matrix2 multiplication
    def matmultiplication(self):
        result12 = self.obj.multiplication1(self.matrix1, self.matrix2,
                                            self.result)
        print("\nMatrix1 and matrix2 multiplication:")
        for temp in result12:
            print(temp)
예제 #5
0
class Probability:
    # class constructor
    def __init__(self):
        # private variable __card for Sample space
        self.__cards = 52
        # Util class object created to call method from that class
        self.obj = UtilClass()

    def calling(self):
        """Write a program to find probability of drawing an ace from pack of cards"""
        # outcomes
        ace = 4
        # round up value is up to 2 decimal
        print("\nProbability of ace: ",
              round(self.obj.probability(ace, self.__cards), 2), '%')
예제 #6
0
class Givenvalues:
    def __init__(self):
        # 1 % womans have breaste cancer i.e P(A) = 0.01
        self.breast_cancer = 0.01
        # womans who doesnt have breast cancer i.e  1 - breast_cancer or (1- P(A))
        self.not_breast_cancer = 0.99

        #  Ninety percent of women who have breast cancer test positive i.e. P(B) = 0.9
        self.positive_breast_cancer = 0.9

        # Eight percent of women will have false positives i.e p(-B) = 0.008
        self.false_breast_cancer = 0.08

        self.obj1 = UtilClass()

    def colling(self):
        print(
            "Probability of positive cancer :",
            self.obj1.prob_positive_cancer(self.breast_cancer,
                                           self.not_breast_cancer,
                                           self.positive_breast_cancer,
                                           self.false_breast_cancer))
class LinearAlgebra:

    # class Constructor
    def __init__(self, matrix1, matrix2, result, vector):
        # self.newname = Parameter
        self.matrix1 = matrix1
        self.matrix2 = matrix2
        self.result = result
        self.vector = vector
        # create obj of utility class
        self.obj = UtilClass()

    # all operation on matrix
    def matrixoperation(self):
        while True:
            try:
                print()
                print("1. Add matrices "
                      "\n"
                      "2. Perform scalar multiplication of matrix and a number"
                      "\n"
                      "3. Perform multiplication of given matrix and vector"
                      "\n"
                      "4. Multiply matrices in problem 1"
                      "\n"
                      "5. Find inverse matrix of matrix "
                      "\n"
                      "6. Find transpose matrix"
                      "\n"
                      "7. Exit")
                ch = input("Enter choice:")
                choice = int(ch)
                if ch.isdigit():
                    if choice == 1:
                        # 1st addition
                        print("addition of two matrix:\n")
                        # Matrix addition
                        value1 = self.obj.matrix_addtn(self.matrix1,
                                                       self.matrix2,
                                                       self.result)

                        # following for loop show addition of two matrices
                        for temp4 in value1:
                            print(temp4)

                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 2:
                        # # 2nd  scalar Matrix multiplication
                        print("Scalar multiplication of two matrix:\n")
                        value3 = self.obj.matrix_scalar_multi(
                            self.matrix1, self.result)
                        # It show addition of two matrices
                        # use loop to display matrix in proper format
                        for temp5 in value3:
                            print(temp5)
                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 3:
                        print("Vector multiplication of two matrix:\n")
                        value5 = self.obj.vectormultiplication(
                            self.vector, self.matrix1)
                        # use loop to display matrix in proper format
                        for temp5 in value5:
                            print(temp5)
                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 4:
                        # 4. multiplication
                        print("Multiplication of two matrix:\n")
                        value2 = self.obj.matrix_multiplication(
                            self.matrix1, self.matrix2)
                        # It show matrix_multiplication
                        # use loop to display matrix in proper format
                        for temp3 in value2:
                            print(temp3)
                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 5:
                        print("Inverse of matrix:\n")
                        value1 = self.obj.inverse_matrix(self.matrix1)
                        for temp in value1:
                            print(temp)

                    elif choice == 6:

                        print("Transpose of matrix:")
                        self.obj.transpose_matrix(self.matrix1)

                        print(
                            "---------------------------OR-----------------------"
                        )

                        print("Transpose of matrix:")
                        value1 = self.obj.transpose(self.matrix1)
                        # use loop to display matrix in proper format
                        for temp in value1:
                            print(temp)

                        print(
                            "---------------------------OR-----------------------"
                        )

                        print("\nTranspose of matrix:")
                        self.obj.trans_matrix(self.matrix1)
                    elif choice == 7:
                        exit()
                        print(
                            "_______________________________________________________________________________"
                        )

                    else:
                        print("Plz enter valid choice: ")

                    acc = str(input("IF you want to continue: type yes "))
                    if re.match(acc, 'y'):
                        continue
                    elif re.match(acc, 'yes'):
                        continue
                    elif re.match(acc, 'n'):
                        break
                    elif re.match(acc, 'no'):
                        break
                    else:
                        print("Give proper input")
                        continue

                else:
                    raise ValueError
            except ValueError as e:
                print("\nInvalid Input", e)
예제 #8
0
 def __init__(self):
     # private variable __card for Sample space
     self.__cards = 52
     # Util class object created to call method from that class
     self.obj = UtilClass()
class Probability:
    # class constructor
    def __init__(self):
        # private variable __card for Sample space
        self.__cards = 52

        # Util class object created to call method from that class
        self.obj = UtilClass()

    def calling(self):
        while True:
            try:
                print(
                    "1.  probability of drawing an ace from pack of cards "
                    "\n"
                    "2. probability of drawing an ace after drawing a king on the first draw"
                    "\n"
                    "3. probability of drawing an ace after drawing an ace on the first draw "
                    "\n"
                    "4 . Exit")

                ch = input("Enter choice:")
                choice = int(ch)
                if ch.isdigit():

                    if choice == 1:
                        """1. Write a program to find probability of drawing an ace from pack of cards"""
                        # outcomes
                        ace = 4
                        # round up value is up to 2 decimal
                        print(
                            "\nProbability of ace: ",
                            round(self.obj.probability(ace, self.__cards), 2),
                            '%')

                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 2:
                        print("\nProb of ace after drawing a King",
                              round(self.obj.ace_after_king(self.__cards), 2),
                              '%')
                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 3:
                        print("\nProb of ace after drawing an Ace",
                              round(self.obj.ace_after_ace(self.__cards), 2),
                              '%')
                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 4:
                        exit()

                    else:
                        print("Plz enter valid choice: ")

                    acc = str(input("IF you want to continue: type yes "))
                    # if acc == 'y' and acc == 'yes':
                    if re.match(acc, 'y'):
                        continue
                    elif re.match(acc, 'yes'):
                        continue
                    elif re.match(acc, 'n'):
                        break
                    elif re.match(acc, 'no'):
                        break
                    else:
                        print("Give proper input")
                        continue

                else:
                    raise ValueError

            except ValueError as e:
                print("\nInvalid Input", e)
 def __init__(self):
     # from super class, init method override
     super(ProbOfRainTrafficLate, self).__init__()
     self.obj1 = UtilClass()
class ProbOfRainTrafficLate(AllValues):
    # class constructor created
    def __init__(self):
        # from super class, init method override
        super(ProbOfRainTrafficLate, self).__init__()
        self.obj1 = UtilClass()

    def calling1(self):

        while True:
            try:
                print()
                print(
                    "1.  probability that it's not raining and there is heavy traffic and I am not late "
                    "\n"
                    "2. What is the probability that I am late"
                    "\n"
                    "3. I arrived late at work, what is the probability that it rained that day "
                    "\n"
                    "4. Exit")
                ch = input("Enter choice:")
                choice = int(ch)
                if ch.isdigit():

                    if choice == 1:
                        # Probability (notRainy . Traffic . NotLate)
                        print(
                            "Probability of Not rainy, traffic, not late:",
                            self.obj1.not_rainy_not_late(
                                self.not_rainy, self.not_rainy_traffic,
                                self.not_rainy_traffic_not_late))

                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 2:
                        # Probability ( I am Late today)
                        print(
                            "Probability of I am late Today:",
                            self.obj1.prob_late(
                                self.rainy_traffic_late,
                                self.rainy_not_traffic_late,
                                self.not_rainy_traffic_late,
                                self.not_rainy_not_traffic_late))
                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 3:
                        # Probability (Rainy day, and I arrived Late)
                        print(
                            "Probability of I arrived late and rainy day:",
                            self.obj1.prob_late_rain(
                                self.rainy_traffic_late,
                                self.rainy_not_traffic_late))

                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 4:
                        exit()

                    else:
                        print("Plz enter valid choice: ")

                    acc = str(input("IF you want to continue: type yes "))
                    # if acc == 'y' and acc == 'yes':
                    if re.match(acc, 'y'):
                        continue
                    elif re.match(acc, 'yes'):
                        continue
                    elif re.match(acc, 'n'):
                        break
                    elif re.match(acc, 'no'):
                        break
                    else:
                        print("Give proper input")
                        break

                else:
                    raise ValueError

            except ValueError as e:
                print("\nInvalid Input", e)
예제 #12
0
class CoinToss:

    # class constructor
    def __init__(self):
        # Util class object created to call method from that class
        self.obj = UtilClass()

    def calling1(self):

        while True:
            try:
                print()
                print(
                    "1. What is the probability of three heads, HHH "
                    "\n"
                    "2. What is the probability that you observe exactly one heads"
                    "\n"
                    "3. you have observed at least one heads, what is the probability that "
                    "you observe at least two heads "
                    "\n"
                    "4. Exit")
                ch = input("Enter choice:")
                choice = int(ch)
                if ch.isdigit():

                    if choice == 1:

                        list11 = [
                            'HHH', 'TTT', 'HTH', 'HTT', 'THH', 'THT', 'HHT',
                            'TTH'
                        ]
                        # calculate probability of three heads
                        result12 = self.obj.three_heads(list11)
                        result123 = str(result12)
                        if re.match(result123, 'None'):
                            print("Content not matched")
                        else:
                            print("Probability of HHH: ", result123)
                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 2:

                        num = int(
                            input(
                                "\nEnter number how many times you want to toss the coin: "
                            ))

                        if num == 1:
                            list1 = ['H', 'T']
                            # calculate probability exactly one heads
                            res = self.obj.removeduplicate(
                                self.obj.permu(list1, num))
                            self.obj.atleast_onehead(res)

                        elif num == 2:
                            ll1 = ['T', 'H', 'T', 'H']
                            result1 = self.obj.removeduplicate(
                                self.obj.permu(ll1, num))
                            self.obj.atleast_onehead(result1)

                        elif num == 3:
                            ll1 = ['T', 'H', 'T', 'H', 'H', 'T']
                            # list11 = ['HHH', 'TTT', 'HTH', 'HTT', 'THH', 'THT', 'HHT', 'TTH']
                            res = self.obj.removeduplicate(
                                self.obj.permu(ll1, num))
                            self.obj.atleast_onehead(res)
                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 3:
                        num = int(
                            input(
                                "\nEnter number how many times you want to toss the coin: "
                            ))

                        if num == 1:
                            list1 = ['H', 'T']
                            res = self.obj.removeduplicate(
                                self.obj.permu(list1, num))
                            self.obj.two_head(res)

                        elif num == 2:
                            ll1 = ['T', 'H', 'T', 'H']
                            result1 = self.obj.removeduplicate(
                                self.obj.permu(ll1, num))
                            self.obj.two_head(result1)

                        elif num == 3:
                            ll1 = ['T', 'H', 'T', 'H', 'H', 'T']
                            # list11 = ['HHH', 'TTT', 'HTH', 'HTT', 'THH', 'THT', 'HHT', 'TTH']
                            res = self.obj.removeduplicate(
                                self.obj.permu(ll1, num))
                            self.obj.two_head(res)

                        print(
                            "_______________________________________________________________________________"
                        )

                    elif choice == 4:
                        exit()

                    else:
                        print("Plz enter valid choice: ")

                    acc = str(input("IF you want to continue: type yes "))
                    # if acc == 'y' and acc == 'yes':
                    if re.match(acc, 'y'):
                        continue
                    elif re.match(acc, 'yes'):
                        continue
                    elif re.match(acc, 'n'):
                        break
                    elif re.match(acc, 'no'):
                        break
                    else:
                        print("Give proper input")
                        break

                else:
                    raise ValueError

            except ValueError as e:
                print("\nInvalid Input", e)
예제 #13
0
 def __init__(self):
     # Util class object created to call method from that class
     self.obj = UtilClass()
 def __init__(self):
     self.obj = UtilClass()
 def __init__(self):
     # create obj of utility class
     self.obj = UtilClass()