相关疑难解决方法(0)

Python中的switch语句的替换?

我想在Python中编写一个函数,它根据输入索引的值返回不同的固定值.

在其他语言中,我会使用switchcase声明,但Python似乎没有switch声明.在这种情况下,推荐的Python解决方案是什么?

python switch-statement

1719
推荐指数
32
解决办法
149万
查看次数

如何用Python创建评分系统?

我有一项学校作业,其中一项任务是显示学生将获得的成绩。等级为:

  • 答:90%+
  • 乙:80% - 89%
  • C: 70% - 79%
  • 深度:60% - 69%
  • 乙:50% - 59%

以下是该文件的一些内容,它是一个以逗号分隔的 CSV 文件:

StudentName Score
Harrison    64
Jake    68
Jake    61
Hayley  86
Run Code Online (Sandbox Code Playgroud)

我想知道/获得一些指导,以便我更好地了解如何创建成绩计算器。我花了很长时间试图解决这个问题,但没有希望。我的代码:

def determine_grade(scores):
    if scores >= 90 and <= 100:
        return 'A'
    elif scores >= 80 and <= 89:
        return 'B'
    elif scores >= 70 and <= 79:
        return 'C'
    elif scores >= 60 and <= 69:
        return 'D'
    elif scores >= 50 and <= 59:
        return 'E'
    else:
        return 'F'
Run Code Online (Sandbox Code Playgroud)

python

-9
推荐指数
1
解决办法
7万
查看次数

标签 统计

python ×2

switch-statement ×1