pythonvisual-studio-codeindentationread-eval-print-loop

Shift+enter inserts extra indents


I have a Python source file with some dummy code:

a = 3
if a == 1:
    print("a = 1")
elif a == 2:
    print("a = 2")
else:
    print("Other")

When I submit the code to terminal with shift+enter, I get the following error. It looks like VS Code changed the indentation of my code. The same code ran just fine with shift+enter on my other computer. The error message is as below:

PS C:\Users\win32> & C:/Users/win32/AppData/Local/Programs/Python/Python313/python.exe
Python 3.13.0 (tags/v3.13.0:60403a5, Oct  7 2024, 09:38:07) [MSC v.1941 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> a = 3
>>> if a == 1:
...         print("a = 1")
...         elif a == 2:
...                     print("a = 2")
...                     else:
...                                 print("Other")
... 
  File "<python-input-1>", line 3
    elif a == 2:
    ^^^^
SyntaxError: invalid syntax

Any insights?


Solution

  • bug: Python3.13 All functions fail to send: IndentationError: unexpected indent

    Use python 3.12