1

I want to create a special calculator using python but for doing this I should know more about complex numbers. My calculator must get a string and output complex equation. Please help me.

myinput = "5 + 2j"
myoutput = ConvertToComplex(myinput) * (3 + 12j)  #please help me with writing this function
print(myoutput)
2
  • I would suggest using a tuple - With one element being the real component and the other element being the imaginary component. You can the process it as you like Commented Aug 10, 2018 at 10:07
  • use a tuple to store the real & imaginary components. then write a function to multiply two such tuples and return another tuple. Commented Aug 10, 2018 at 10:10

1 Answer 1

4

The function you are looking for is already built into python. You just need to get rid of whitespace first:

myinput = "5 + 2j"
mycleaninput = myinput.replace(" ","")
myoutput = complex(mycleaninput) * (3 + 12j)
print(myoutput)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.