Python Can';t将复数转换为浮点

Python Can';t将复数转换为浮点,python,Python,我在这段代码中遇到了一个错误,我尝试了很多方法,但它仍然说: 回溯(最近一次呼叫最后一次): 文件,第7行 TypeError:无法将复数转换为浮点 代码如下: import math a = float(input()) x = complex((a**1/3)*math.exp(0)*1j) y = complex((a**1/3)*math.exp(((2*math.pi)/3)*1j)) z = complex((a**1/3)*math.exp(((4*math.pi)/3)*1j

我在这段代码中遇到了一个错误,我尝试了很多方法,但它仍然说:

回溯(最近一次呼叫最后一次): 文件,第7行 TypeError:无法将复数转换为浮点

代码如下:

import math

a = float(input())
x = complex((a**1/3)*math.exp(0)*1j)
y = complex((a**1/3)*math.exp(((2*math.pi)/3)*1j)) 
z = complex((a**1/3)*math.exp(((4*math.pi)/3)*1j))

print(complex(x).real)
print(complex(x).imag)
print(complex(y).real)
print(complex(y).imag)
print(complex(z).real)

print(complex(z).imag)
math.exp()
不支持复杂参数。您需要
cmath.exp()

>math.exp(1j)
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
TypeError:无法将复数转换为浮点
>>>cmath.exp(1j)
(0.5403023058681398+0.8414709848078965j)

请参阅。

欢迎来到SO。请正确格式化您的代码。
>>> math.exp(1j)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can't convert complex to float
>>> cmath.exp(1j)
(0.5403023058681398+0.8414709848078965j)