Is there a better way?

In my Trigonometry class, we were assigned to find the discriminant and conic section of an equation…

I wrote a function that calculates the discriminant, and then based on the value of the discriminant, prints the conic section…

I’m just curious if there is a better, more effective way to write this…

def disc():
    a_disc = ("Please enter the value of A: ")
    b_disc = ("Please enter the value of B: ")
    c_disc = ("Please enter the value of C: ")
    disc = b_disc**2-4*(a_disc)*(c_disc)
    print ("The discriminant is: %s") % (disc)
    if disc < 0:
        if a_disc != c_disc:
            print "The conic is an Ellipse."
        elif a_disc == c_disc:
            print "The conic is a Circle."
    elif disc > 0:
        print "The conic is a Hyperbola."
    elif disc == 0:
        print "The conic a Parabola."
        print "Something went wrong :-("

I don’t fully understand using arguments inside of functions, but I feel like doing something like:


would be the more clean approach I guess.

I would really appreciate any feedback anyone has to offer. Thanks in advance!

Yes. Functions should preferably communicate only through arguments and return values, no other side-effects.

Reason: maintainability

1 Like