Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re^3: solve cubic equations (Python)

by LanX (Cardinal)
on May 05, 2017 at 17:56 UTC ( #1189595=note: print w/replies, xml ) Need Help??

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

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!

Replies are listed 'Best First'.
Re^4: solve cubic equations (Python)
by no_slogan (Deacon) on May 05, 2017 at 18:43 UTC
    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
        I guess most people do, but I don't care for it. If I have an integer, I need to use // to divide, or it gets converted to a float. If I have a Fraction, I need to use /, or it gets converted to an integer. You say, "but // always produces an integer, that's so much easier." But I don't see why there has to be a special operator devoted to integers.
        >>> from fractions import Fraction >>> x = Fraction(22,7) >>> y = 3 >>> print(x,x/2,x//2) 22/7 11/7 1 >>> print(y,y/2,y//2) 3 1.5 1
Re^4: solve cubic equations (Python)
by Anonymous Monk on May 05, 2017 at 18:31 UTC
    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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1189595]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (10)
As of 2020-10-01 07:47 GMT
Find Nodes?
    Voting Booth?
    If at first I donít succeed, I Ö

    Results (176 votes). Check out past polls.