Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions pygorithm/math/quadratic.py
Original file line number Diff line number Diff line change
@@ -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)