[Tutor] Unexpected Indent Error Message
Alan Gauld
alan.gauld at yahoo.co.uk
Fri Mar 27 13:24:50 EDT 2020
On 27/03/2020 15:38, Alan Thwaits wrote:
> I'm trying to run a script I've copied from Exercise 43 of Zeb Shaw's
> "Learn Python the Hard Way." But I'm getting an "unexpected indent" error
> message.
Peter has highlighted the immediate problem causing the error. But I
wonder if that's all...
> class EscapePod(Scene):
>
> def enter(self):
> print(dedent("""
...> """))
>
> good_pod = randint(1,5)
> guess = input("[pod #]> ")
Notice that these lines are not indented to the same level
as the print statement.
That means they are not part of the enter() method.
But they are part of the class definition.
Now that is legal Python, but it's extremely unusual Python.
So I suspect these lines and all that follow should be
indented under the print() statement?
Indentation is key in python. Arguably that's a good thing
since it forces your code to be formatted in a readable style,
but you do need to keep your eyes peeled because it can
trip you up.
HTH
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list