[Tutor] Unexpected Indent Error Message

Alan Gauld alan.gauld at yahoo.co.uk
Fri Mar 27 15:32:54 EDT 2020


On 27/03/2020 17:45, Alan Thwaits wrote:
> I tried that, with this resulting code:

A large part of the problem is the trple quoted strings are obscuring
the stricture of your code. Take them out(assign them to variables at
the top of the code then print the varoiables) It looks like:


> 
> class EscapePod(Scene):
> 
>     def enter(self):
>         print(foo)
> 
>     good_pod = randint(1,5)
>     guess = input("[pod #]> ")
> 
>     if int(guess) != good_pod:
>         print(bar")
>         return 'death'
>     else:
>         print(baz)
> 
>         return 'finished'



Notice how your indentation is too far left.
So the return is associated with the code starting
good_pod=
Which is not inside a function.

And return outside a function is illegal, so python complains.


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