Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from math import acos
- class MathFunction:
- def __validate(self):
- if not self.n > 0:
- raise IOError
- def __init__(self, x, y, n):
- self.x = int(x)
- self.y = int(y)
- self.n = int(n)
- self.__validate()
- def __compute(self):
- total = 1
- for i in range(self.y):
- total *= self.x
- return total
- def __myfactorial(self):
- result = 1
- n = self.n
- while n > 1:
- result *= n
- n -= 1
- return result
- def __solveA(self):
- return self.__compute() / self.__myfactorial()
- def __solveB(self, a): #ayusin mo nalang formula nito sa solve b
- ax = 2 * a * self.x
- arccos = acos(0.235 * self.n)
- y3 = self.y * self.y * self.y
- root = 1
- return ax + (arccos / (root/y3))
- def show(self):
- a_result = round(self.__solveA(), 4)
- b_result = round(self.__solveB(a_result), 4)
- print("Result for solveA: %s" % a_result)
- print("Result for solveB: %s" % b_result)
- def inputdata():
- x = input("Enter X: ")
- y = input("Enter Y: ")
- n = input("Enter N: ")
- return MathFunction(x, y, n)
- if __name__ == "__main__":
- repeat = True
- while repeat:
- try:
- solver = inputdata()
- solver.show()
- inp = input("Do you want to continue? y/n >>")
- repeat = inp == "y" or inp == "Y"
- except IOError:
- print("Please enter a positive number for n. Try again")
- continue
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement