[Tutor] Unexpected Indent Error Message

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


I've aligned 'death' with the print above it (checking with VSCode to be
certain of the alignment), and get the following:

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-1-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 158
    return 'death'
    ^
SyntaxError: 'return' outside function

Perhaps this means that I need to look at function somewhere else in the
script. Any suggestions re where or what?

Thanks!

Alan

On Fri, Mar 27, 2020 at 12:57 PM Baptista Albert <ireneprajay at gmail.com>
wrote:

> Hi Alan,
>
> Your return 'Death' and the print above it should align, I see 1space in
> the alignment of the return statement.
>
> Hope this helps,
>
>
> On Fri, Mar 27, 2020, 11:53 AM Alan Thwaits <basicbare at gmail.com> 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.
>>
>> Here's the guilty block of script I've copied (and checked umpteen times
>> for accuracy):
>>
>> class EscapePod(Scene):
>>
>>     def enter(self):
>>         print(dedent("""
>>             You rush through the ship, desperately trying to make it to
>> the
>> escape pod before the ship explodes. It seems like hardly any Nastics are
>> on the ship, so your run is clear of interference. You get to the escape
>> pod chamber, and now need to pick a pod. Some of them could be damaged,
>> but
>> you don't have time to look. There are five pods. Which one do you take?
>>             """))
>>
>>     good_pod = randint(1,5)
>>     guess = input("[pod #]> ")
>>
>>
>>     if int(guess) != good_pod:
>>         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'
>>     else:
>>         print(dedent("""
>>             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 here's the error message I get back:
>>
>> Type "copyright", "credits" or "license" for more information.
>>
>> IPython 7.8.0 -- An enhanced Interactive Python.
>>
>> 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-1-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 158
>>     return 'death'
>>     ^
>> IndentationError: unexpected indent
>>
>> For the life of me, I can't figure out what I've done wrong. I've gone
>> through the code line-by-line. I've used VSCode's grid markings to check
>> that the indents all line up properly. I've tried various indent/tab/space
>> settings. I've learned a lot about indent/dedent. But no joy.
>>
>> Can anyone see from the above snippets where I've gone wrong?
>>
>> Thanks!
>>
>> Alan
>> _______________________________________________
>> 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