why is the result of 2**5 is not float and 9**1/2 is float ? thanks in advance!!
6/28/2019 8:34:35 PM
Yeabsira Yetagessu13 Answers
New AnswerIn Python, when using the division operator (/) or doing division of any sort, you always get float, unless you explicitly convert it to a integer, Yeabsira Yetagessu . So 2**5 returns an integer (32) while 9**1/2 (9 to the power of 1 divided by 2) returns a float (4.5) Hope this helps 😊
In Python 3, when you do division the answer will always be a float, unless you do int(9**1/2). This code would evaluate to 4.
Doing a square root will always give a float, even when it would be an integer in the same way that doing a division will give a float even when that would be an integer. 4/2 gives 2.0 and not 2 and, in the same way 9**0.5 gives 3.0 and not 3.
When you square an integer with a float the answer becomes a float These three examples may help you out: 1:Integer * or / Float = Float 4 * or / 2.0 = 6.0 or 2.0 2:Integer * or / Integer = Integer 4 * or / 2 = 6 or 2 3:Float * or / Float = Float 4.0 * or / 2.0 = 6.0 or 2.0
Yeabsira Yetagessu because if the power of the number is integer, the result must be integer. But if the power of the number is float, the result may be integer or float so compiler choice float and there are a different between 9**1/2 and 9**(1/2)
please tell me clearly what is the meaning ** or // in python, why we use double..... please explain it clearly
chris check out the tutorials on YouTube, the might help you if you don't understand these
Why was $0.01 used for the code and not 1,000,000? print(0.01 * (2**30)) Why? Thank you.
Sololearn Inc.
535 Mission Street, Suite 1591Send us a message