problem with complex number - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: problem with complex number (/thread-17496.html) |
problem with complex number - jodrickcolina - Apr-13-2019 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: 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 Z, I put for example: 5+5j In Y, I put 2j and this is the problem: I need to work with complex number but I don't know how to covert str to "complex"
RE: problem with complex number - Yoriz - Apr-13-2019 Turn the input str into a complex number using complex https://docs.python.org/3/library/functions.html?highlight=complex#complex Wrote:class complex([real[, imag]]) |