Problem with Python 3.5.0

Matt Wheeler m at funkyhat.org
Sun Oct 11 15:12:51 EDT 2015


On 11 October 2015 at 18:12, eetix letix <eetix.letix at gmail.com> wrote:
> Hi,
>
> I'm sorry but the last version of Python (3.5.0) had a problem. I start and
> I meet this problem :
>
>>>>a=5
>>>>if a>0:
> . . .         print("a is a positive.")
> . . . if a<0:
>          ^
> SyntaxError: invalid syntax
>>>>
>
> Normally this should work but problem comes to the fact that Python
> considers "a" is a positive number and refuses to do the command >>>if a<0:

You're almost there, but your guess as to the reason for the error
isn't quite right.

It seems that the syntax in the Python shell is subtly different to
code in a module.
Because the second 'if' is a distinct statement from the first, the
python shell seems to require a second return.

However consider that perhaps using an 'else' or 'elif' instead of a
completely separate 'if'
And also consider that most people regard 0 to be positive, so you
probably meant (a>=0).

That means you can simplify to
if a>=0:
    print("a is a positive")
else:
    print("no need to evaluate a a second time")


> And the command \n is doesn't working :
>
>>>> a="test\nto\nsee\nif\nit\nis\nworking"
>>>> a
> 'test\nto\nsee\nif\nit\nis\nworking'
>>>>
>
>
> Normally, \n should make that the text returns to the line but doesn't make
> it. And if y do :
>
>>>> a="""test
> . . .  to
> . . .  see
> . . .  if
> . . .  it
> . . .  is
> . . .  working"""
>>>>a
> 'test\nto\nsee\nif\nit\nis\nworking'
>>>>

\n is an escape sequence rather than a command
Have a look at what happens if you try print(a)


> Thanks to fix this problems and good luck ;)
>
>
> PS : I'm sorry for this really bad english but I'm french and I'm 14

Don't worry, it's certainly better than my French!



-- 
Matt Wheeler
http://funkyh.at



More information about the Python-list mailing list