Python, how to input a complex number
04-30-2021, 08:55 AM (This post was last modified: 04-30-2021 08:58 AM by Stevetuc.)
Post: #6
 Stevetuc Senior Member Posts: 311 Joined: Jan 2014
RE: Python, how to input a complex number
(04-29-2021 06:37 PM)Didier Lachieze Wrote:
(04-29-2021 02:36 PM)Dirk.nl 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 ?

I tested it on the Numworks virtual app and got also an error message, this may be a limitation of Micropython.

Complex() should accept either a string or a number as input.
On the Numworks, it only accepts a number.
Code:
 x=5+1j; x=complex(x);  #this works x=complex(5,1) #this works x="5+1j" x=complex(x) #this doesnt
Since input() returns a string, this also doesn't work.
 « Next Oldest | Next Newest »

 Messages In This Thread Python, how to input a complex number - Dirk.nl - 04-29-2021, 02:36 PM RE: Python, how to input a complex number - Stevetuc - 04-29-2021, 04:02 PM RE: Python, how to input a complex number - Dirk.nl - 04-29-2021, 05:04 PM RE: Python, how to input a complex number - Didier Lachieze - 04-29-2021, 06:37 PM RE: Python, how to input a complex number - Stevetuc - 04-30-2021 08:55 AM RE: Python, how to input a complex number - Albert Chan - 04-30-2021, 10:36 AM RE: Python, how to input a complex number - Dirk.nl - 04-29-2021, 07:20 PM RE: Python, how to input a complex number - Dirk.nl - 04-30-2021, 09:51 AM RE: Python, how to input a complex number - toml_12953 - 04-30-2021, 10:36 AM RE: Python, how to input a complex number - Dirk.nl - 04-30-2021, 10:55 AM RE: Python, how to input a complex number - parisse - 04-30-2021, 11:57 AM RE: Python, how to input a complex number - Dirk.nl - 04-30-2021, 01:21 PM

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