Python "Bad syntax"

Ian Kelly ian.g.kelly at gmail.com
Mon Feb 5 12:25:04 EST 2018


On Mon, Feb 5, 2018 at 10:13 AM,  <darkorbitaknaentou at centrum.cz> wrote:
>
> Hi, I have a problem in continuing the function.
>
> I'm a beginner, I'm learning from a textbook. I'm going to put the following
> examples from a textbook that displays "wrong syntax"

It would be very helpful if you would copy/paste the exact error
message instead of just paraphasing it.

>
>>>>
>>>> for letter in "ABCDEFGHIJKLMNOPQRSTUVWXYZ":
>
>             if letter in "AEIOU":
>                 print(letter, "is a vowel")
>            else:
>                  print(letter, "is a consonant")
>
> In this text, I will write a "wrong syntax" after confirming the "else"
> function. How is it possible? Using the Bad Version of Python? Please,
> please, thank you very much!

Copying this into either Python 2.7 or 3.5, I get IndentationError
(because the indentation of the if and the else is inconsistent), not
SyntaxError. I don't know whether that's what you're seeing or if it
was just a copying error when you wrote the email.

> The same error is in the "break" function:
>
>>>>
>>>> while True:
>
>               item = get_next_item()
>               if not item:
>                    break
>               process_item(item)
>
> Here 'wrong syntax' occurs after the "break".

I don't get a syntax error from this at all. I just get NameError
because get_next_item is not defined. If it and process_item were both
defined, I expect this would run.



More information about the Python-list mailing list