From e077afaab7f4d8225e8b65516d149ccc09600dca Mon Sep 17 00:00:00 2001 From: antnguyen33 <55636711+antnguyen33@users.noreply.github.com> Date: Sat, 28 Sep 2019 22:00:43 -0400 Subject: [PATCH] Add files via upload --- pygorithm/math/quadratic.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 pygorithm/math/quadratic.py diff --git a/pygorithm/math/quadratic.py b/pygorithm/math/quadratic.py new file mode 100644 index 0000000..b1084d8 --- /dev/null +++ b/pygorithm/math/quadratic.py @@ -0,0 +1,22 @@ +""" +Author: Anthony Nguyen +Created On: 28 September 2019 +""" + +import math + + +def quadratic(): + """ + This function returns the x values that are the solutions to a quadratic equation given a, b, and c + + The quadratic equation is formed by ax^2+bx+c=0 + """ + a = float(input('Enter a:')) + if a == 0: + return 'You cannot have "a" be 0 in a standard quadratic equation. Try again.' + b = float(input('Enter b: ')) + c = float(input('Enter c: ')) + d1 = math.sqrt((b ** 2) - (4 * a * c)) + d2 = -1 * (math.sqrt((b ** 2) - (4 * a * c))) + return ((-1 * b) + d1) / (2 * a) and ((-1 * b) + d2) / (2 * a)