math.sqrt 有问题_带有Python示例的math.sqrt()方法

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 有问题

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值