Complex numbers calculator

440 views Asked by At

So, if I type (4*9j**2) into the console, it returns (-324+0j) Is there any way to re-create this with code, basically, take input and simplify it as if you just typed it into the console (j acts as the imaginary number i)

Thanks in advance!

1

There are 1 answers

0
import random On

You can use the built in function eval().

>>> 4*9j**2
(-324+0j)
>>> equation = "4*9j**2"
>>> eval(equation)
(-324+0j)