Post Reply 
Python, how to input a complex number
04-29-2021, 04:02 PM (This post was last modified: 04-29-2021 04:13 PM by Stevetuc.)
Post: #2
RE: Python, how to input a complex number
(04-29-2021 02:36 PM) Wrote:  According to Python documents, you can enter a complex number like this; var=complex(input())
For example, 3+5j
The Python App gives an error message here.
Could someone for me test / try this and explain what I'm doing wrong ?
Looking online, it seems input cannot directly pass a complex number to complex().
I haven't tried this, but it's suggested to take a string as input then convert to complex number:


a = input() # user will enter 3+5j 
a = complex(a) # then this will be converted into complex number.

Edit: hmm ignore my post, other posts at tht url suggest your syntax should work as is.
Find all posts by this user
Quote this message in a reply
Post Reply 

Messages In This Thread
RE: Python, how to input a complex number - Stevetuc - 04-29-2021 04:02 PM

User(s) browsing this thread: 1 Guest(s)