#Basic operators not working

1 messages · Page 1 of 1 (latest)

olive ferry
#

I have some very basic calculations that simply don't work and I cannot figure out why.

while i < 6:
  print(dice_faces[i])
  print(number_of_faces)
  print(float(dice_faces[i]/number_of_faces))
  print(float(1/6))
  dice_odds[i] = int(dice_faces[i])/int(number_of_faces)
  i = i + 1                        

This prints out:
1
6
0.0
0.0

I have no clue why; just none.

wide widget
#

integer division throws out the fractional part, so if you do 1/6, you get ~0.1667, which, because it's integer division, gets rounded down to 0, which is then converted to a float 0.0

olive ferry
#

So should

while i < 6:
                print(float(dice_faces[i]))
                print(float(number_of_faces))
                print(float(dice_faces[i]/number_of_faces))
                print(float(1/6))
                dice_odds[i] = int(dice_faces[i])/int(number_of_faces)```

work?
wide widget
#

no, because you're still dividing integers

#

you're just conerting the parts that you print to float

olive ferry
#

I’m a moron; thanks