This question already has answers here:
What does the ** maths operator do in Python?
(5 answers)
Closed 5 months ago.
import math
def countSquares(x):
sqrt=x**0.5
result=int(sqrt)
return result
x=81
print(countSquares(x))
x**0.5 is "x to the power of 0.5" which essentially means square root of x.
Related
This question already has answers here:
Why is exponentiation applied right to left?
(4 answers)
Closed 2 years ago.
print (2**3**2)
Answer is 512.
Why 512 is answer not 64? Because ((2^3)^2) = 64
I want to know the inside math operation of print (2** 3**2)
The order of operations for exponentiation is right-to-left, not-left-to right. So:
2**3**2
is interpretted as:
2**(3**2) = 2**(9) = 512
This question already has answers here:
Why is exponentiation applied right to left?
(4 answers)
Closed 2 years ago.
Am New to python trying out some basic python function. Came across exponential
In python
2 ** 2 ** 3 is 256
But while in mathematics getting as 64.
Use parentheses. This will give the correct answer.
(2 ** 2) ** 3
Use parentheses
x = (2**2)**3
or:
pow(2,2*3)
This question already has answers here:
Is floating point math broken?
(31 answers)
Python floating-point math is wrong [duplicate]
(2 answers)
Closed 4 years ago.
For example:
In: -0.01 + (-0.02) + (-0.4) + (-0.05)
Out: -0.48000000000000004
Instead of -0.48
Why does it happen so?
And how to avoid such situations?
This question already has answers here:
Python Perfect Square
(3 answers)
Check if a number is a perfect square
(25 answers)
Closed 5 years ago.
I wrote this alternative to finding if a number was a perfect square or no how can I fix this:
n = input ('type n ')
message = ('false')
if n>0 and (math.sqrt(n)).is_integer(): message = ('true')
print (message)
This question already has answers here:
Math operations from string [duplicate]
(8 answers)
Closed 6 years ago.
I have a string with a formula 5 - 3, and I need to get the result in integer. How could I do that?
use eval function:
eval("5 - 3") # 2
test = "5-3"
print(eval(test))
Gives 2