math.sqrt 有问题
Python math.sqrt()方法 (Python math.sqrt() method)
math.sqrt() method is a library method of math module, it is used to find the square root of a given number, it accepts a positive number (integer or float) and returns square root.
math.sqrt()方法是math模块的库方法,用于查找给定数字的平方根,它接受正数(整数或浮点数)并返回平方根。
Note:
注意:
If the given number is a negative number, it returns a "ValueEroor" – "ValueError: math domain error".
如果给定数字为负数,则返回“ ValueEroor” – “ ValueError:math domain error” 。
If we provide anything like string, except a number, it also returns a "ValueError" – "TypeError: a float is required".
如果我们提供字符串以外的任何东西,除了数字,它还会返回一个“ ValueError” – “ TypeError:需要浮点数” 。
Syntax of math.sqrt() method:
math.sqrt()方法的语法:
math.sqrt(n)
Parameter(s): n – a number whose square root needs to be calculated.
参数: n-一个需要计算平方根的数字。
Return value: float – it returns a float value that is the square root of given number n.
返回值: float-它返回一个浮点值,该浮点值是给定数字n的平方根。
Example:
例:
Input:
a = 2
# function call
print(math.sqrt(a))
Output:
1.4142135623730951
Python代码演示math.sqrt()方法的示例 (Python code to demonstrate example of math.sqrt() method)
# python code to demonstrate example of
# math.sqrt() method
# importing math module
import math
# numbers
a = 2
b = 12345
c = 10.21
d = 0
e = 0.0
# finding square roots of the numbers
print("square root of ", a, " is = ", math.sqrt(a))
print("square root of ", b, " is = ", math.sqrt(b))
print("square root of ", c, " is = ", math.sqrt(c))
print("square root of ", d, " is = ", math.sqrt(d))
print("square root of ", e, " is = ", math.sqrt(e))
Output
输出量
square root of 2 is = 1.4142135623730951
square root of 12345 is = 111.1080555135405
square root of 10.21 is = 3.1953090617340916
square root of 0 is = 0.0
square root of 0.0 is = 0.0
翻译自: https://www.includehelp.com/python/math-sqrt-method-with-example.aspx
math.sqrt 有问题