+ 3

Learning python

Do I’m inputting the same example written here on my computer but the result is different does anyone knows why? 9**(1/2) R= 1 On the example the result is 3

20th Dec 2018, 5:31 AM
Angel Lo
Angel Lo - avatar
9 Respuestas
+ 2
Are you using python 2.x on your computer?
20th Dec 2018, 5:50 AM
Anna
Anna - avatar
+ 5
that worked Anna thanks Diego Acero
20th Dec 2018, 6:11 AM
Angel Lo
Angel Lo - avatar
+ 4
yeah i did
20th Dec 2018, 5:42 AM
Angel Lo
Angel Lo - avatar
+ 4
0
20th Dec 2018, 5:49 AM
Angel Lo
Angel Lo - avatar
+ 4
2.7
20th Dec 2018, 5:54 AM
Angel Lo
Angel Lo - avatar
+ 4
For Python 2.x, dividing two integers uses integer division, also known as “floor division”. That’s why 1/2 = 0. Thus, 9**(1/2) = 9**(0) = 1.
20th Dec 2018, 6:02 AM
Diego
Diego - avatar
+ 4
Try 9**(1.0/2)
20th Dec 2018, 6:06 AM
Anna
Anna - avatar
+ 3
That’s weird! Are you sure you wrote the same expression in your computer?
20th Dec 2018, 5:40 AM
Diego
Diego - avatar
+ 2
Could you please do the division (1/2) in your computer? What is the output?
20th Dec 2018, 5:48 AM
Diego
Diego - avatar