On 25/03/14 19:21, Saad Bashir wrote:

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.


Do you actually get the three dots in your IDLE? I don't in mine...
And thats important because in my IDLE I have to align my indentation with the left margin rather than the code above.
So your code would look like:

>>> if ph < 7.0:
       print(ph, "is acidic.")
elif ph > 7.0:
       print(ph, "is basic.")

in my IDLE.

That's pretty ugly and I wish the IDLE guys would fix it but
it's been that way for a long time.

Basically you have to pretend the first line started on
the left margin...

--
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

Reply via email to