Taz a écrit :
20/600 = 0 en calcul entier. informatique ou pas. si tu veux faire du cacul flottant (approximation des réels) alors utilise des float comme opérandes et fait 20.0/600.0
|
En Python, ça va changer avec la mise en place de la PEP 238 "Changing the Division operator", qui est déjà disponible sous forme de __future__ import:
Code :
>>> 3/5 # Classic integer division 0 >>> 3//5 # Classic floordivision 0 >>> 3./5 # Classic float division 0.59999999999999998 >>> 3.//5 # Classic floordivision 0.0 >>> from __future__ import division >>> 3/5 # "True Division" 0.59999999999999998 >>> 3//5 # Floor division 0 >>> 3./5 # "True division" 0.59999999999999998 >>> 3.//5 # Floor division" 0.0 >>>
|
Ce comportement passera (normalement) en comportement par défaut avec Python 3.
Message édité par masklinn le 12-04-2006 à 12:54:05
---------------
I mean, true, a cancer will probably destroy its host organism. But what about the cells whose mutations allow them to think outside the box, and replicate and expand beyond their wildest dreams by throwing away the limits imposed by overbearing genetic r