0

Why is 10 / 2 5.0 not 5?

Why is 10 / 2 5.0 not 5 if it has the meaning of divisor? (phyton)

20th Oct 2018, 6:51 PM
PixelGamer
PixelGamer - avatar
2 Respostas
+ 3
ints and floats are different data types. When you divide something, Python automatically makes the result a float - because it might have decimals, right? If you don't want that, you can use // instead. But if you then divide let's say 11 by 2, the result will be 5.
20th Oct 2018, 6:57 PM
HonFu
HonFu - avatar
+ 2
Like HonFu said Python use float variables If you want 5 you can do: print(int(10/2))
20th Oct 2018, 9:16 PM
Med Arezki
Med Arezki - avatar