0
If print(10/2) shows result as 5.0 , print(10//2) shows 5 then print(10*2) shows 20.0 but print(10**2) is showing 100.0 why?
5 odpowiedzi
+ 5
Kpranav K
/ is the Division Operator, will return a float
// is the floor Division operator, which will round down to the next whole number (integer Division), will return an int
* is multiplication operator. It will return an int, when both operands are int, else it will return a float.
** is power operator, like ^x, will return an int, when both operands are int, else it will return a float.
Now, With the above, print(10*2) will indeed Show 20, not 20.0.
Instead print(10.0*2) will show 20.0..
In case, you want to surely have an int, you could convert it accordingly.
print(int(10.0*2)) will show 20.
You could also use round, ceil, floor, depending on your needs.
+ 3
Try to run 10 ** 2, and it will return an integer.
Remember that the result or answer will be float if atleast one of the number is float, or the operation is division.
https://code.sololearn.com/c4BOmqAKw3T8/?ref=app
+ 1
Hi! Becouse 10**2 == 10^2 == 10² == 10 *10 == 100
+ 1
print(10*2) outputs "20". If you want to print it as 20.0 you can do print(float(10*2))
print(10**2) outputs 100. Again you can convert to float to output 100.0
0
x**y is like x^y, so if you print(10**2), then it will be 10^2, 10*10, which means 100