I have Python 3.8(32-bit) installed, and I am using Atom to write my attempts and then copy-pasting them into the Python terminal.
The following code is copied directly from the very beginning of an introductory Python course I am taking "for fun":
n = 5
while n > 0:
print(n)
n=n-1
print('Blastoff!')
The code works in every sandbox I can find, and the last line works on its own in my terminal. But when I copy it to my terminal, I get an invalid syntax error that points to the word print
. I can fix this and get the desired output by changing my code to:
n = 5
while n > 0:
print(n)
n=n-1
else:
print('Blastoff!')
But I have three issues with this:
- Why does my original code not work, as it is copied directly from the course?
- I need to hit Enter twice after copying in that second block of code for it to run. Why is that?
- Why does Atom insist on indenting the last
print
farther than my other indents?
Here is what I am seeing when entering my first code brick:
>>> n = 5
>>> while n > 0:
... print(n)
... n=n-1
... print('Blastoff!')
File "<stdin>", line 4
print('Blastoff!')
^
SyntaxError: invalid syntax
quit()
to exit the interpreter and you'll be back inside the windows command prompt. If you've already exited the python interpreter, you can writepython blastoff.py
in the windows command prompt, and it will run your file. Let me know if it's not clear the distinction between the windows command prompt and the python interpreter. – hkennyv