On 7/30/2019 10:24 PM, Sara Mistral wrote:
I downloaded Python recently on my computer and I have some troubles
making it work. It doesn’t allow me to make and if function and elif
without the good indentation. I have the latest version of Python
(3.7.4) and my mac is updated (macOS Mojave 10.14.5).
As you can see in the picture,
Most python mail lists do not allow binary attachments. idledev
currently does, but attachments do not follow responses. It is also
impossible to copy from images to determine what you entered. Please
copy and paste instead of attaching screenshots.
>>> if a > 0:
print('positive')
if a < 0:
SyntaxError: invalid syntax
With 3.7.3 on my Mac and 3.7.4 on my Windows machine, the second 'if' is
highlighted as an error with black type on brownish red background.
But I don't see this on your screenshot.
Did you create a custom theme with this disabled? If you go to Options
=> Configure IDLE => Hightlight tab and select Builtin theme IDLE
classic, is the word 'error' not so highlighted?
the “if” doesn’t align properly.
You have mixed together two issues. First the syntax: '>>> ' in IDLE's
Shell means 'Enter *one* python statement. An 'if' statement can be
followed by multiple 'elif' line and one 'else' line. The second 'if'
starts a second statement, which is an error when your entry is
interpreted as one statement. The following single statement works.
>>> if a > 0:
print('positive')
elif a < 0:
print('negative')
else:
print('zero')
positive
I tried with else, elif, if, and every time I hit “send” it sends me to the
wrong indentation.
Second, the indentation. The 'if', 'elif', and 'else' lines have the
same indentation: none. You have to ignore the prompt. It is not
counted as indentation. This awkward convention, and the use of tabs,
is a side-effect of Shell's feature of working with statements instead
of physical lines. I am preparing a new tracker issue to do away with
prompts interfering with code and tab indents. It will make code entry
in Shell the same as in IDLE's editor, so one could enter
if a > 0:
print('positive')
elif a < 0:
print('negative')
else:
print('zero')
positive
the same in both places.
My dad needs this for his work and he’s trying to learn Python but sadly
he is stuck.
Not really. Believe SyntaxError and try to get the error highlighting
working.
--
Terry Jan Reedy
_______________________________________________
IDLE-dev mailing list
IDLE-dev@python.org
https://mail.python.org/mailman/listinfo/idle-dev