mirror of
https://github.com/keanuplayz/dotfiles.git
synced 2024-08-15 02:33:12 +00:00
[scripts/pycalc] add a simple as a rock quadratic equation solver
This commit is contained in:
parent
570307f0bc
commit
4b0865b150
1 changed files with 17 additions and 0 deletions
|
@ -11,4 +11,21 @@ def factors(n):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def solve_quadratic(a, b, c):
|
||||||
|
if a == 0:
|
||||||
|
raise Exception("not a quadratic equation")
|
||||||
|
else:
|
||||||
|
d = b ** 2 - 4 * a * c
|
||||||
|
print("D = " + str(d))
|
||||||
|
if d < 0:
|
||||||
|
print("no solutions")
|
||||||
|
elif d > 0:
|
||||||
|
sd = sqrt(d)
|
||||||
|
print("sqrt(D) = " + str(sd))
|
||||||
|
print("x1 = " + str((-b + sd) / (2 * a)))
|
||||||
|
print("x2 = " + str((-b - sd) / (2 * a)))
|
||||||
|
else:
|
||||||
|
print("x = " + str(-b / (2 * a)))
|
||||||
|
|
||||||
|
|
||||||
print("loaded Python calculator")
|
print("loaded Python calculator")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue