In Python 2.7.8, it’s impossible to find the square root and the exponent.
- pythonworld.ru/moduli/modul-math.html - Alex Krass
- @ Valentine, If you are given an exhaustive answer, mark it as correct (click on the check mark next to the selected answer). - Vitalina
|
3 answers
As already written earlier, you can use the functions from the standard math
module. To do this, you need to connect to the program. Usage is as follows:
import math x = float(input()) print(math.sqrt(x)) print(math.exp(x))
If desired, you can use it without a prefix, in which case you can use a different import syntax:
from math import sqrt, exp x = float(input()) print(sqrt(x)) print(exp(x))
To find the square root, you can also use the exponentiation operator or the pow
function (since the square root is the exponentiation to the power of 0.5):
x = float(input()) print(x ** 0.5) print(pow(x, 0.5))
Discussion on how to take the root using pow
, ** 0.5
, math.sqrt
on enSO
|
math.exp math.sqrt
- does not work! - Valentine
- I thought so too - Valentine
- one@ Valentina, explain in more detail what exactly does not work. Show the code you are trying to run, what happens at startup. - BogolyubskiyAlexey
- Type "help", "copyright", "credits" or "license" for more information. >>> import math >>> a = input () 0.5 >>> b = input () 10 >>> x = sqrt (float (a)) / exp (float (a)) Traceback (most recent call last) : File "<stdin>", line 1, in <module> NameError: name 'sqrt' is not defined >>> - Valentine
- oneI understood, it is necessary to specify math at each appeal to functions. Then it works. Thank! - Valentine
|
math.sqrt(a/b)
|