Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new function quadratic() #90

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
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)