We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,440 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

what other ways are there to make a quadratic formula program in python?

hello, i was only wondering if there were other ways of making a quadratic formula calculator in python.
i recently made one my self by making a module i named quadratic which is shown below:

def get_coefficients():
    a = float(raw_input('a = '))
    b = float(raw_input('b = '))
    c = float(raw_input('c = '))
    return (a,b,c)


def calculate_solutions(a, b, c): 
    if a == 0:
        return None
    else:
        under_radical = b*b - 4*a*c
        if under_radical < 0:
            return None
        else:
            root = math.sqrt(under_radical)

            solution1 = (-b + root) / a * 2
            solution2 = (-b - root) / a * 2
            return (solution1, solution2)

def print_solutions(solutions):
    if solutions == None:
        print 'no solution'
    else:
        print solutions[0]
        print solutions[1]

i then made the actual program:

import quadratic

print 'hello quadratics'

a,b,c = quadratic.get_coefficients()
solutions = quadratic.calculate_solutions(a, b, c)
quadratic.print_solutions(solutions)

again, i was only wondering if there were other ways of doing this, thank you.

4
Contributors
3
Replies
15 Hours
Discussion Span
3 Months Ago
Last Updated
22
Views
kindergeek
Newbie Poster
1 post since Mar 2013
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
joejoeBOB
Newbie Poster
2 posts since Mar 2013
Reputation Points: 7
Solved Threads: 1
Skill Endorsements: 2
pyTony
pyMod
Moderator
6,330 posts since Apr 2010
Reputation Points: 879
Solved Threads: 989
Skill Endorsements: 27

You can make your module give real and complex solutions.

Lardmeister
Posting Virtuoso
1,940 posts since Mar 2007
Reputation Points: 465
Solved Threads: 73
Skill Endorsements: 5

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page generated in 0.0600 seconds using 2.69MB