[Python] What is wrong with my pretty simple code? I can't run a pretty simple if-elif-else...

Discussão em 'Python' iniciado por Stack, Junho 11, 2025.

  1. Stack

    Stack Membro Participativo

    I have consulted with different LLMs and searched the net for it, but still, I can't solve this issue. No matter how I write this code, I still get an error! This is a screenshot of my coding environment. Here is the code:

    stuff = 42

    if stuff < 10:
    print("Low")

    elif 10 <= stuff < 40:
    print("Medium")

    else:
    print("High")


    This is what python returns:


    >>> stuff = 42
    >>> if stuff < 10:
    ... print("Low")
    ... elif 10 <= stuff < 40:
    ... print("Medium")
    ... else:
    ... print("High")
    ...
    File "<python-input-3>", line 3
    elif 10 <= stuff < 40:
    ^^^^
    SyntaxError: invalid syntax


    I have tried different LLMs, which give answers that don't work (The error in your code is due to incorrect indentation in the else block). I know that the code is alright, so I suspect that the problem is probably with my IDE or venv.

    Here are alternative tries:

    # try 1
    if stuff < 10:
    print("Low")
    elif 10 <= stuff < 40:
    print("Medium")
    else:
    print("High")

    # try 2
    if stuff < 10:
    print("Low")
    elif 10 <= stuff < 40:
    print("Medium")
    else:
    print("High")

    Continue reading...

Compartilhe esta Página