[Python] Multiple lines in a for loop in VS Code with Python

Discussão em 'Python' iniciado por Stack, Maio 19, 2025.

  1. Stack

    Stack Membro Participativo

    I have just started learning Python in VS Code but can't get VS Code to run the following for loop to produce list of the first 10 square values:

    squares = [] for value in range(0,11):
    square = value ** 2
    squares.append(square) print(squares)


    I get the following error:

    >>> squares = []
    >>> for value in range(0,11): \\ square = value ** 2 \\ squares.append(square) \\

    File "<python-input-428>", line 3
    squares.append(square)
    IndentationError: unexpected indent


    If I remove the second indent, this is asking the programme to do something different to what I want. I cant work out were I'm going wrong in VS Code.

    When I save the code as a .py file and run the file in Command Prompt the programme runs find. Can anyone tell me where I'm going wrong in VS Code please.

    Continue reading...

Compartilhe esta Página