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?

22nd Oct 2021, 3:46 AM
Tawanda Makuvise
Tawanda Makuvise - avatar
6 Answers
+ 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?
22nd Oct 2021, 4:02 AM
ChaoticDawg
ChaoticDawg - avatar
+ 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
22nd Oct 2021, 4:52 AM
Python Learner
Python Learner - avatar
+ 3
Tawanda Makuvise Can you attach your code for us to look at
22nd Oct 2021, 4:22 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 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'>
22nd Oct 2021, 4:12 AM
ChaoticDawg
ChaoticDawg - avatar
+ 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 👆
22nd Oct 2021, 4:26 AM
Tawanda Makuvise
Tawanda Makuvise - avatar
0
I am using version 3
22nd Oct 2021, 4:03 AM
Tawanda Makuvise
Tawanda Makuvise - avatar