2024-04-30 00:59:04 发布
网友
我被传递一个实数和一个虚数,x和y组成一个复数
考虑到这一点,我有一个方法sqrt,我需要找到一个复数的正平方根。构造函数名称以返回的complex形式给出。 我知道我应该使用cmath,但我该怎么做呢
def sqrt(self): sqrtnum = self.cmath.sqrt() return ComplexS(?, ?)
import cmath def sqrt(z): sqrtnum = cmath.sqrt(z) return sqrtnum print (sqrt(3+2j)) print (sqrt(4))
输出:
(1.8173540210239707+0.5502505227003375j) (2+0j)
输出:
相关问题 更多 >
编程相关推荐