[Tutor] 2 Very basic queries
Jim Byrnes
jf_byrnes at comcast.net
Wed Mar 26 02:32:53 CET 2014
On 03/25/2014 02:21 PM, Saad Bashir wrote:
> Hi everyone!
>
> I am a novice programmer and actually learning to program in Python. I have
> two issues that I am embarrassed to present as they seem to be extremely
> basic.
>
> 1. But encouraged by the site to ask event the most basic questions on
> this forum, here goes:
>
> I am using the book:
>
> Practical Programming: an introduction to computer science using Python 3.
>
> As per its instructions I am using the IDLE environment (Python shell) of
> Python [3.2.3 MSC v.1500 64 bit AMD64]. I have been going through the book
> without any problems but have become stuck at the following stage:
>
> When using "if" and "elif" statement I get two types of error messages:
>
> 1. Practicing the code as given in the book:
>
> >>> ph = float(input('Enter the pH level: '))
> Enter the pH level: 8.5
>>>> if ph < 7.0:
> ... print(ph, "is acidic.")
> ... elif ph > 7.0:
> ... print(ph, "is basic.")
>
> When I write this in the Python shell, as soon as I hit return after "elif
> ph > 7.0:"
> I get an error message highlighting "elif" and saying syntax error.
>
> Or if I try the indentation as follows with elif aligned if above I get the
> message below:
>
>>>> ph = float(input('Enter the pH level: '))
> Enter the pH level: 8.5
>>>> if ph < 7.0:
> ... print(ph, "is acidic.")
> ... elif ph > 7.0:
> ... print(ph, "is basic.")
>
> "SyntaxError: : unindent does not match any outer indentation level.
>
> I have tried everything I can think of but to no avail. Please help.
>>> ph = float(input('Enter the ph level: '))
Enter the ph level: 8.5
>>>
>>> if ph < 7.0:
print(ph, 'is acidic.')
elif ph > 7.0:
SyntaxError: unindent does not match any outer indentation level
>>> if ph < 7.0:
print(ph, 'is acidic.')
elif ph > 7.0:
print(ph, 'is basic.')
8.5 is basic.
I am also learning Python and find idle hard to use. My first if/elif
pair looks perfectly aligned but gives a SyntaxError, while my second
if/elif pair looks to be not aligned but works fine.
I imagine there is a better explanation but here is how I think of it.
Python seems to ignore the >>> and considers the i starting if to be in
column 0, so if you put your elif against the left margin it works.
>
> 2. Another problem is that the Python shell is allowing me to copy/paste
> any code at all. Is there something I am not doing right?
I was able to copy from idle using Ctrl-C and paste to my newreader
using Ctrl-V and then copy from my newsreader back to idle using the
same procedure. I am using Linux and you seem to be using Windows may
be it works differently so I can't help you with it.
Regards, Jim
More information about the Tutor
mailing list