I have a problem when I wanna work with complex number in python 3, the problem is that I do not know how to convert a string to "complex" when I save a complex number in a variable, for example, the next code:
In Z, I put for example: 5+5j
In Y, I put 2j
and this is the problem:
1 2 3 4 5 6 7 |
import math import cmath print ( "calculo de las constantes generalizadas" ) Z = input ( "ingrese el parametro Z ohm/km: " ) Y = input ( "ingrese el parametro Y siemen/km: " ) g = cmath.sqrt(Z * Y) print (g) |
In Y, I put 2j
and this is the problem:
Error:Traceback (most recent call last):
File "C:/Users/Usuario/AppData/Local/Programs/Python/Python37-32/test.py", line 6, in <module>
g=cmath.sqrt(Z*Y)
TypeError: can't multiply sequence by non-int of type 'str'
I need to work with complex number but I don't know how to covert str to "complex"