0
I am doing the simple operation part but I why the answer would be 6.0 why not only 6 according to the question?????????????????
????????????????? !float!?????????????????
3 Respostas
+ 1
I get ittttt
(4+8)/2 right?
"/" operator do float division.That's it :D
So if you want integer division or floor division
(4+8)//2
so if you do this
print((4+8)/2)
you get 6.0 on screen/Terminal
0
In real life, when you divide 4/2, you get 2, but when you divide 5/2 you get 2.5.
So the point just shows up if it's needed, right?
In computers, whole integers (int) are a different data type to numbers with decimals (float), so there needs to be some conversion to handle it.
In other languages like C, when you divide an int by an int, you *always* get an int.
So 5/2 would be 2. The decimals just get cut off.
Python is normal-person friendly in the way that it automatically converts as soon as there *could* be decimals.
So whenever you use division, you will get a float as a result, even if there are no decimals.
4/2 -> 2.0
5/2 -> 2.5
0
In real life, when you divide 4/2, you get 2, but when you divide 5/2 you get 2.5.
So the point just shows up if it's needed, right?
In computers, whole integers (int) are a different data type to numbers with decimals (float), so there needs to be some conversion to handle it.
In other languages like C, when you divide an int by an int, you *always* get an int.
So 5/2 would be 2. The decimals just get cut off.
Python is regular-person friendly in the way that it automatically converts as soon as there *could* be decimals.
So whenever you use division, you will get a float as a result, even if there are no decimals.
4/2 -> 2.0
5/2 -> 2.5