Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | igbow |
Hi What would print((300/500) ) show on the screen ?
I’m getting 0.
Am I doing something wrong ?
Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | igbow |
Hi What would print((300/500) ) show on the screen ?
I’m getting 0.
Am I doing something wrong ?
Reply From: | kidscancode |
That’s called “Integer division”. Because both numbers are integers, the result (0.6
) is cast to integer as well, which results in 0
.
If you want a float answer, at least one of the operands needs to be a float: print(300.0/500)
or even print(float(300)/500)
Thank you so much Love your tutorials !!!
igbow | 2019-06-14 18:42