quadratic_equations.py

Created by alain-busser

Created on May 26, 2019

182 Bytes

To solve a (quadratic) equation, means to compute the set of its solutions. This script does exactly that: Compute a set (https://en.wikipedia.org/wiki/Solution_set). It does not compute a list or a string or whatever (else than a set), nor does it display anything, it just solves an equation, giving the set of its solutions. Just enter quadratic_solve(2,5,3) to solve the equation 2x²+5x+3==0


def quadratic_solve(a,b,c):
  S = set([])
  Delta = b**2-4*a*c
  if Delta >= 0:
    r=Delta**0.5
    S.add((-b-r)/(2*a))
    S.add((-b+r)/(2*a))
  return S

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.