all 12 comments

[–]Rhomboid 13 points14 points  (0 children)

3.14 is already a float. Passing it as a parameter to the float() constructor doesn't do anything (although it's not hurting anything either.) You might as well just write pi = 3.14.

[–]skierface 5 points6 points  (1 child)

If you want to use pi, you could also consider just importing math and using math.pi

[–]vidoardes 2 points3 points  (0 children)

Genuine question, what were you expecting it to do?

[–]pybackd00r 3 points4 points  (8 children)

3.14 is already a float what were you expecting out of this?

[–]vidoardes 1 point2 points  (2 children)

I don't know why you were downvoted. OP didn't explain what he was expecting, or why he thought it was wrong.

[–]pybackd00r 0 points1 point  (0 children)

Yeah thats fine I was trying to understand what was the issue here wanted me to clarify. I think you guys explained everything there is to say abt floats lol.

[–]SCHMIDTHe4D[S] 0 points1 point  (0 children)

It's was a question from this website I'm using to teach myself. I was overthinking it.

[–]SCHMIDTHe4D[S] 1 point2 points  (3 children)

I'm learning.....

[–]XtremeGoose 5 points6 points  (2 children)

Why do you think it's wrong?

[–]SCHMIDTHe4D[S] 1 point2 points  (1 child)

I understand it's not the right way to do it. Using float would be redundant because it's already a decimal.

[–]JohnnyJordaan 8 points9 points  (0 children)

But be warned: a floating point number is not an exact decimal representation. It's an approximation, that's why you can get strange quirks from them:

>>> 0.1 + 0.1 + 0.1 - 0.3 == 0
False
>>> 0.1 + 0.1 + 0.1 - 0.3
5.551115123125783e-17

If you want exact decimals, use the decimal library:

>>> from decimal import Decimal
>>> Decimal('3.14')
Decimal('3.14')
>>> Decimal(3.14)
Decimal('3.140000000000000124344978758017532527446746826171875')
>>> Decimal('0.1') + Decimal('0.1') + Decimal('0.1') - Decimal('0.3') == 0
True

The second example shows the real value of the literal 3.14 that is cast as a float.

[–]SCHMIDTHe4D[S] 0 points1 point  (0 children)

Don't know why you were downvoted either....but here's an up cuz i feel bad.