[Tutor] Unexpected Indent Error Message

Alan Thwaits basicbare at gmail.com
Fri Mar 27 13:45:27 EDT 2020


I tried that, with this resulting code:

class EscapePod(Scene):

    def enter(self):
        print("You rush through the ship, desperately trying to make it to
the escape pod before the whole ship explodes. It seems like hardly any
Nastics are on the ship, so your run is clear of interference. You get to
the chamber with the escape pods, and now need to pick one to take. Some of
them could be damaged, but you don't have time look closely. There are five
pods, Which one do you take?")

    good_pod = randint(1,5)
    guess = input("[pod #]> ")

    if int(guess) != good_pod:
        print("You jump into pod {guess} and hit the eject button. The pod
slides easily into space, heading to the planet below. Then, as the hull
ruptures, it implodes, crushing your body like jam jelly.")
        return 'death'
    else:
        print("You jump into pod {guess} and hit the eject button. The pod
slides easily out into space, heading to the planet below. As it flies down
to the planet, you back, and see the ship implode, then explode like a
bright star. It takes out the Nastic ship at the same time. You won!")

        return 'finished'

And got this error message:

runfile('C:/Users/Alan/Documents/Python/ex43.py',
wdir='C:/Users/Alan/Documents/Python')
Traceback (most recent call last):

  File
"C:\Users\Alan\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py",
line 3326, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)

  File "<ipython-input-6-ceaa7049971f>", line 1, in <module>
    runfile('C:/Users/Alan/Documents/Python/ex43.py',
wdir='C:/Users/Alan/Documents/Python')

  File
"C:\Users\Alan\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py",
line 827, in runfile
    execfile(filename, namespace)

  File
"C:\Users\Alan\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py",
line 110, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "C:/Users/Alan/Documents/Python/ex43.py", line 153
    return 'death'
    ^
SyntaxError: 'return' outside function

Which is the same as what I got originally.

Am I being dumb? Clumsy?

Thanks!

Alan



On Fri, Mar 27, 2020 at 1:17 PM Peter Otten <__peter__ at web.de> wrote:

> Alan Thwaits wrote:
>
> If instead of the fancy dedent(<multiline-string>)
>
> >         print(dedent("""
> >             You jump into pod {guess} and hit the eject button. The pod
> > escapes out into the void of space. Then it implodes as the ship's hull
> > ruptures, crushing your body into jam jelly.
> >             """))
> >             return 'death'
>
> you print something simple
>
>          print("Hi")
>              return 'death'
>
> I'm sure you can't miss the problem :)
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>


More information about the Tutor mailing list