in reply to Re: solve cubic equations (Python)
in thread solve cubic equations

This code does not produce the right answer.
It produces
(-9.433363736780528, -9.433363736780528, -9.433363736780528)
Adding ".0" to all the numbers in the code seems to help.

Replies are listed 'Best First'.
Re^3: solve cubic equations (Python)
by LanX (Saint) on May 05, 2017 at 17:56 UTC
    Yep that's Python, if the first assignment (declaration) is an integer the variable is typed to be an integer and all operators will only perform integer operations.

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!

      Python variables aren't typed. The result type is determined by the value (in Perl, it's usually determined by the operator). Float-vs-int-division is one of the annoying unnecessary incompatibilities in python3.
      > python2.7 -c 'print(5/2)' 2 > python3.5 -c 'print(5/2)' 2.5
      Precisely why Python is faster than Perl at runtime. If you would spend your energy learning new tools instead of cursing them ... oh right ... we are talking about LanX.
Re^3: solve cubic equations (Python)
by Anonymous Monk on May 05, 2017 at 16:03 UTC
    Thanks. The point was simply to show how using the right tool for the job leads to a cleaner solution. For all things string related, I would pick Python as a last resort.