Post Reply 
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
RE: Python, how to input a complex number
(04-29-2021 06:37 PM)Didier Lachieze Wrote:  
(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 ?

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

[Image: mini_210429084530470275.png] [Image: mini_210429083642969630.png] [Image: mini_210429084529667009.png]

Complex() should accept either a string or a number as input.
On the Numworks, it only accepts a number.

x=complex(x);  #this works
x=complex(5,1) #this works

x=complex(x) #this doesnt
Since input() returns a string, this also doesn't work.
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-30-2021 08:55 AM

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