i am getting an error "Code is unreachable Pylance" what that mean or am i doing any mistake in my code?

Question:

def percent(marks):
    return (marks[0]+marks[1]+marks[2]+marks[3]/400)*100

    marks1=[54,65,85,54]
    percent1=percent(marks1)

    marks2=[54,52,65,85]
    percent2 = percent(marks2)
    print(percent1,percent2)
Asked By: Anuj

||

Answers:

The lines after return will not be executed anytime. So you can delete them and nothing will change. The message told you about it, because it is very unusual to have such code.

I think you wanted this:

def percent(marks):
    return (marks[0]+marks[1]+marks[2]+marks[3]/400)*100

marks1 = [54, 65, 85, 54]
percent1 = percent(marks1)

marks2 = [54, 52, 65, 85]
percent2 = percent(marks2)
print(percent1, percent2)

Spaces in Python code matter. In your code all lines are the part of the function. In fixed code they are not.

Answered By: ceth

i know why code is unreachable its because the interpreter thinks your program has closed.
Something like exit()
what is under exit() the code interpreter thinks cannot be executed, But it can be executed!

Answered By: heyo

For anyone coming across this Stack Overflow question wondering how to disable this feature in which Pylance greys out text which it (often mistakenly) thinks is unreachable, a solution is provided by luabud in this comment and this comment on the GitHub issue How to disable "code is not reachable"…, which is to place the following entry in your user/workspace settings.json file:

    "[python]": {
        "editor.showUnused": false,
    },
Answered By: Jake Levi
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.