OK, You are using IDLE and have discovered one of its "features" 
which I consider a bug...

The alignment of code breaks in IDLE when there is no >>> in the line. 
You need to ignore the >>> characters.

So, to IDLE, your code looks like

if x < 0:
           print(...)
      elif x == 0:

because IDLE doesn't see the >>>.


So it gives you the unindent error because it thinks elif is not aligned 
with if, even though it looks that way to you...

To fix it you need to make it look like this on screen:

>>> if x < 0:
            print(...)
elif x == 0:
      print(....)
else:
      print(....)

Which looks wrong to you and me but IDLE sees it as good.

And this is one of the rare cases where posting an image rather 
than a cut n' paste of the code is actually useful, because it 
shows that you are using IDLE...

HTH
Alan Gauld
Author of the Learn To Program website
http://www.alan-g.me.uk/

http://www.flickr.com/photos/alangauldphotos



>________________________________
> From: Gregory Donaldson <gvdon...@gmail.com>
>To: Alan Gauld <alan.ga...@btinternet.com> 
>Sent: Sunday, 14 September 2014, 4:28
>Subject: Re: [Tutor] If statement The Python Tutorial 3.4.1
> 
>
>
>
>​
>
>
>
>On Sat, Sep 6, 2014 at 7:49 PM, Alan Gauld <alan.ga...@btinternet.com> wrote:
>
>On 06/09/14 00:29, Gregory Donaldson wrote:
>>
>>
>>This is what it looks like when I try to get it to work.
>>>
>>>
>>>x = int(input("Please enter an integer: "))
>>>>>>
>>>Please enter an integer: 42
>>>
>>>
>>>if x < 0:
>>>>>>
>>>x = 0
>>>
>>>print('Negative changed to zero')
>>>
>> I'm guessing that you actually indented the two lines
>>above but not the one below - otherwise you'd get an
>>indentation error by now, not a syntax error below.
>>
>>
>>elif x == 0:
>>>
>>>SyntaxError: invalid syntax
>>>
>> Are you sure this is where you get the syntax error?
>>Or did you maybe hit enter too many times thus ending
>>the if block?
>>
>>
>>It needs to follow this pattern:
>>
>>if x < 0:
>>   x = 0
>>   print('Negative changed to zero')
>>elif x == 0:
>>    print('you typed zero')
>>else:
>>   print('alls well')
>>
>>So the if/elif and else lines are all lined up with each
>>other and the indented lines are likewise lined up.
>>And if working in the interactive prompt you must not
>>have blank lines (Note: You can have blanks when creating
>>a program file)
>>
>>Indentation is always important in programming for readability,
>>but in Python its vital for Python to understand your code
>>correctly.
>>
>>HTH
>>-- 
>>Alan G
>>Author of the Learn to Program web site
>>http://www.alan-g.me.uk/
>>http://www.flickr.com/photos/alangauldphotos
>>
>>
>>_______________________________________________
>>Tutor maillist  -  Tutor@python.org
>>To unsubscribe or change subscription options:
>>https://mail.python.org/mailman/listinfo/tutor
>>
>
>
>
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to