skip to Main Content

I’m starting to learn and this issues are really frustrating.

I have this simple code that works on the terminal smoothly:

user_prompt = "entra un PorHacer:"
porHaceres = []

while True:
    accion = input("¿Qué hacemos?")
    accion = accion.capitalize()
    match accion:
        case 'A':
            porHacer = input("Introduce tu porHacer:")
            porHaceres.append(porHacer.capitalize())
        case 'V':
            print(porHaceres)
        case 'S':
            break

But using VScode play button it gives me this message:
File "c:/Scripts/Py 001/Course.31.py", line 7
match accion:
^
SyntaxError: invalid syntax

Which is the VScode not recognizind the match-case function (the "case" in this issue)

How can I fix this disturbing problem?

I tried uninstalling and reinstalling pylance, Microsoft python extension, and so on… changing the variable names and tested the code in online interpreters and in the VScode terminal and it worked. Don’t understand why i can¡’t execute it directly on VScode

2

Answers


  1. The match keyword was added to Python in version 3.10.

    Your VS Code must be using an older version of Python, that does not know about the match keyword.

    Login or Signup to reply.
  2. Your syntax might not be supported by VSCode, as the match-case syntax here is only supported by Python 3.10 and later. You should check your python version like this:

    python --version
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search