0
Hie Guys, why is it the result of this print (2*5) is 10.0 which is a float, but the result of this print (2**5) is 32 an integ
Why is it that the result of multiplying two integers is a float but the result of exponentiating two integers is an integer?
6 odpowiedzi
+ 4
I'm guessing this is in Python? If so, 2 * 5 results in 10 an integer as well. If you are getting a float, what version of Python are you using?
+ 4
Hi Tawanda!
print(a*b) never return float unless one of them(a or b) is a float.
You may try this
print(2.0*5) --> 10.0
print(2*5.0) --> 10.0
print(2*5) --> 10
+ 3
Tawanda Makuvise
Can you attach your code for us to look at
+ 2
You can try running this;
print(2 * 5) # 10
print(type(2 * 5)) # <class 'int'>
print(2 ** 5) # 32
print(type(2 ** 5)) # <class 'int'>
+ 1
1. print (2 * 5) the result here is 10.0 a float.
2. print (2 ** 5) the result is 32 an integer.
Those are the codes 👆
0
I am using version 3