+ 1

Why am i getting 0 as output in Python

Print(24/26)

12th Dec 2018, 5:37 PM
Sotomi Oluwadmilola
5 odpowiedzi
+ 4
Okay, so if you tried doing something like this in Python 2.x: print 24/26 it would perform floor division, which gives the integer not exceeding the actual result of the division. In Py 2.x, you'd need to do 24.0/26 or 24/26.0 to get accurate result, like Mert suggested.
12th Dec 2018, 6:31 PM
Kishalaya Saha
Kishalaya Saha - avatar
+ 7
In Python2, a / b returns an integer if both a and b are integers. You should convert one of them to float to have float result 2 / 4 -> 0 2.0 / 4 -> 0.5
12th Dec 2018, 5:55 PM
Mert Yazıcı
Mert Yazıcı - avatar
+ 3
Hi Sotomi Oluwadmilola That's strange! Are you using Python 3.x? If so, you shouldn't get zero as output. Could you please save your code in the Code Playground and share a link with us? Thanks!
12th Dec 2018, 5:48 PM
Kishalaya Saha
Kishalaya Saha - avatar
+ 2
We called the float in Python.
12th Dec 2018, 6:14 PM
program
program - avatar
0
My Python editor is an old version.. Code worked well in the code playground
12th Dec 2018, 6:27 PM
Sotomi Oluwadmilola