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.

Gribouillis commented: nice +14

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.

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. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.