python - 我收到错误 "Code is unreachable Pylance"这是什么意思,或者我在我的代码中做错了什么?

标签 python python-3.x

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)

最佳答案

return 之后的行不会随时执行。所以你可以删除它们,什么都不会改变。消息告诉你这件事,因为有这样的代码是很不寻常的。

我想你想要这个:

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)

Python 代码中的空格很重要。在您的代码中,所有行都是函数的一部分。在固定代码中,它们不是。

关于python - 我收到错误 "Code is unreachable Pylance"这是什么意思,或者我在我的代码中做错了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68789213/

相关文章:

python-3.x - 如何在FastAPI中将文件多文件上传字段设置为可选字段

python-3.x - 从 AWS Lambda 上的 S3 读取文件时出现 IncompleteReadError

python - 在Python中将年度累计数据转换为月度绝对值

python - Travis-CI 找不到 python3-pip 包

python - 如何在 Python 三元运算符上换行?

python - 如何将时间数据转换为数值?

python-3.x - 属性错误 : module 'yaml' has no attribute 'warnings'

python - 加速风险 war 游戏掷骰子模拟

python - 该函数一次又一次地运行,没有任何类型的循环

python - 使用 bool AND 计算行中字符串的出现次数