1
0
Fork 0
mirror of https://github.com/nbrooks211/zommath2 synced 2024-12-24 13:24:38 -05:00
zommath2/zommath2.py

58 lines
1.2 KiB
Python
Raw Normal View History

2020-01-20 13:00:35 -05:00
from math import sqrt
def bogocalc(buy, get, discount, price):
total = buy + get
buy_cost = buy * price
get_cost = get * price
unitprice = buy_cost + get_cost * (1 - discount / 100)
return unitprice / total
class Quadratic:
def __init__(self, a=None, b=None, c=None):
self._a = a
self._b = b
self._c = c
def set_nums(self, a, b, c):
self._a = a
self._b = b
self._c = c
def deter(self):
return self._b**2 - 4 * self._a * self._c
def plusans(self):
top_plus = self._b - sqrt(self.deter())
plus_ans = top_plus / (2 * self._a)
return plus_ans
def minusans(self):
top_minus = self._b + sqrt(self.deter())
minus_ans = top_minus / (2 * self._a)
return minus_ans
def __str__(self):
return f"{self._a}x^2 + {self._b}x + {self._c}"
if __name__ == "__main__":
q = Quadratic(1, 2, -3)
print(f"-2 ± √({q.deter()})")
for a in range(1, 10):
q.set_nums(a, 2, -3)
print(f"Solving: {q}")
print(f"Plus ans: {q.plusans()}")
print(f"Minus ans: {q.minusans()}")
print(f"Determinant: {q.deter()}")
#3 for 3 sale
#buy x get y z% off`