[Tutor] Unexpected Indent Error Message
Alan Thwaits
basicbare at gmail.com
Fri Mar 27 11:38:38 EDT 2020
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
More information about the Tutor
mailing list