All pastes #979674 Raw Edit

Someone

public text v1 · immutable
·published 2008-04-10 14:54 UTC
rendered paste body
import clr
import sys
import System.Double
import System.Console
import System.Math

def InputVar(q):
    """ Inputs text from the console, parses it and returns it as a double """
    print q
    tmp = System.Double.Parse(System.Console.In.ReadLine())
    return tmp

def NumberOfRoots(a, b, c):
    """ Finds the number of roots for a Quadratic Equation """
    
    bsquared = System.Math.Pow(b, 2)
    fourAC = 4 * a * c

    if (bsquared == fourAC):
        return 1
    if (bsquared >= fourAC):
        return 2
    
    return 0

def SolveEq(a, b, c):
    """ Solves a Quadratic Equation """
    
    if(NumberOfRoots(a,b,c) == 0):
        print "Error, Quadratic Equation has no real roots!"
        return

    bsquared = System.Math.Pow(b, 2)
    fourAC = 4 * a * c

    root1 = (((-b) + System.Math.Sqrt(bsquared - fourAC)) / (2 * a))

    print "First Root : " + root1.ToString()

    root2 = (((-b) - System.Math.Sqrt(bsquared - fourAC)) / (2 * a))

    print "First Root : " + root2.ToString()
    
def QuadraticSolver():
    
    print "Welcome to the Quadratic Solver! \n"
    a = InputVar("Enter A:")
    b = InputVar("Enter B:")
    c = InputVar("Enter C:")

    print "A: " + a.ToString() + " B: " + b.ToString() + " C: " + c.ToString()
    print "Number of Roots: " + NumberOfRoots(a, b, c).ToString()

    SolveEq(a, b, c)

QuadraticSolver()