1

Program For Standard Form

def stnfrm(a,b,c):

    one = (b/(2.0*a))
    two = c-((b**2.0)/(4.0*a))
    axis = one/-1.0
    x = -b/(2.0*a)
    y = a*(x**2.0)+(b*x)+c
    print x
    if a == 1:
        print "(x + %f)**2 + (%f)" % (one,two)
    elif a == -1:    
        print "-(x + %f)**2 + (%d)" % (one,two)
    else:
        print "%d(x + %f)**2 + (%f)" % (a,one,two)
    print "Axis of Symmetry is %f" % (axis)
    print "Vertex is (%f,%f)" % (x,y)
    if a < 0:
        print "Vertex is a Maximum"
    else:
        print "Vertex is a Minimun"
stnfrm(2.0,-16.0,31.0)

All you need to do is change the numbers in th stnfrm(?,?,?) at the bottom to deteremine the outcomes.
My first piece of code ive fully written.
I would appreciate some input and ideas going forward.

Edited by Tamara_1: error

Comments
nice
4
Contributors
3
Replies
35
Views
2 Years
Discussion Span
Last Post by ddanbe
Featured Replies
  • 1
    ddanbe 2,525   2 Years Ago

    Just a small remark: use meaningful names for your variables. Do not use things like "one" and "two". And yes, I know. It is sometimes hard to find a good meaningful name, but believe me in larger programs it pays off. :) Read More

0

It is very nice. I see 2 directions onwards:

  1. Add interaction with the user to get the coefficients (raw_input, etc).
  2. Use the fractions module from standard lib to work with exact rational coefficients.
1

Just a small remark: use meaningful names for your variables. Do not use things like "one" and "two".
And yes, I know. It is sometimes hard to find a good meaningful name, but believe me in larger programs it pays off. :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.