- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有这个家庭作业问题要求输入 5 个考试分数并计算等效的字母等级,然后计算平均值并对其应用字母等级。
我目前有一个工作程序,但我想看看是否有可能通过仅使用一组“if”语句来获得所有分数
def letter_grade(test1, test2, test3, test4, test5, average):
if test1 >= 90 and test1 <=100:
score1 = "A"
elif test1 >= 80 and test1 <= 89:
score1 = "B"
elif test1 >= 70 and test1 <= 79:
score1 = "C"
elif test1 >= 60 and test1 <= 69:
score1 = "D"
elif test1 < 60:
score1 = "F"
if test2 >= 90 and test2 <=100:
score2 = "A"
elif test2 >= 80 and test2 <= 89:
score2 = "B"
elif test2 >= 70 and test2 <= 79:
score2 = "C"
elif test2 >= 60 and test2 <= 69:
score2 = "D"
elif test2 < 60:
score2 = "F"
if test3 >= 90 and test3 <=100:
score3 = "A"
elif test3 >= 80 and test3 <= 89:
score3 = "B"
elif test3 >= 70 and test3 <= 79:
score3 = "C"
elif test3 >= 60 and test3 <= 69:
score3 = "D"
elif test3 < 60:
score3 = "F"
if test4 >= 90 and test4 <=100:
score4 = "A"
elif test4 >= 80 and test4 <= 89:
score4 = "B"
elif test4 >= 70 and test4 <= 79:
score4 = "C"
elif test4 >= 60 and test4 <= 69:
score4 = "D"
elif test4 < 60:
score4 = "F"
if test5 >= 90 and test5 <=100:
score5 = "A"
elif test5 >= 80 and test5 <= 89:
score5 = "B"
elif test5 >= 70 and test5 <= 79:
score5 = "C"
elif test5 >= 60 and test5 <= 69:
score5 = "D"
elif test5 < 60:
score5 = "F"
if average >= 90 and average <=100:
avgScore = "A"
elif average >= 80 and average <= 89:
avgScore = "B"
elif average >= 70 and average <= 79:
avgScore = "C"
elif average >= 60 and average <= 69:
avgScore = "D"
elif average < 60:
avgScore = "F"
return score1, score2, score3, score4, score5, avgScore
如果可能的话,我希望函数以更有效的方式返回字母分数。
最佳答案
只需定义函数,然后使用它对每个测试进行评分和平均分:
def letter_grade(score):
if 90 <= score <= 100:
grade = "A"
elif 80 <= score <= 89:
grade = "B"
elif 70 <= score <= 79:
grade = "C"
elif 60 <= score <= 69:
grade = "D"
elif score < 60:
grade = "F"
return grade
tests = [50, 60, 65, 99, 25]
for test in tests:
print(f"score: {test}, grade: {letter_grade(test)}")
print("average grade:", letter_grade(sum(tests) / len(tests)))
Output:
score: 50, grade: F
score: 60, grade: D
score: 65, grade: D
score: 99, grade: A
score: 25, grade: F
average grade: F
关于python - 硬件问题 : Is it possible to convert all the test scores without additional blocks in grading function?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55444713/
虽然 find(["a", "b"], "c") 没有问题,但在尝试查找结构数组中的结构索引时出现错误: struct Score { //... } var scores: [Score]
也许我在 http://guides.rubyonrails.org/layouts_and_rendering.html#using-partials 中遗漏了一些东西 似乎要渲染部分,我们可以使用
我正在发布 Android Facebook 游戏的分数,我返回“真实”,但我在任何地方都看不到这个故事。我错过了什么? 最佳答案 Facebook 似乎有一些逻辑,有时只发布基于分数的故事。 您可以
我有包含一些数据和特定省略列表的文档(参见 mapping 和 example data ): 我想编写一个执行以下操作的 ES 查询: 计算文档的一些“基本”分数(查询 1): { "expla
我是 iOS 开发的新手,我已经成功地集成了 facebook 登录等...但是我的问题是 Score api。我可以阅读乐谱,但我似乎无法发布它,我拥有 publish_actions 权限,并且正
如果我有 2 个标签(1 和 0),并且在我通过 softmax 激活层传递我的 logits 之后,我得到如下内容: [[0.1, 0.9], [0.3, 0.7], [0.333, 0.667]]
我正在使用 k 折交叉验证来计算加法平滑参数 alpha 的最佳值。另外,我想根据 alpha 值绘制训练准确度和验证准确度的曲线。我为此编写了代码: alphas = list(np.arange(
我使用的示例摘自《Mastering Machine Learning with scikit learn》一书。 它使用决策树来预测网页上的每个图像是否是一个广告或文章内容。然后可以使用级联样式表隐
我使用 scipy.cluster.hierarchy.linkage 作为聚类算法并将结果链接矩阵传递给 scipy.cluster.hierarchy.fcluster ,以获得扁平化的集群,用于
我有以下代码,我想用它来检查用户答案并输出分数(满分 5 分)。我使用包含答案的 plist 并检查 textField.text 。我正在努力解决的是:如何使用这种方法获得总输出分数? - (IBA
我知道还有很多其他类似的问题与该领域有关,但没有一个答案有效。就我而言,我有以下代码,我试图按分数降序对记录数组进行排序。 function score(string, pattern){ str
我希望能够保留玩家在玩我的游戏时获得的分数,以及当他们关闭游戏并重新打开游戏时分数仍然保存。我能想到的唯一方法是使用文本文件来完成此操作,就像我在 VB6 中所做的那样。但是,这意味着他们可以编辑文本
现在我已经完成了我的游戏制作,我需要添加的是应用内购买和排行榜,并且为了不搞砸我正在使用测试应用做的任何事情。我的排行榜现在正在显示,即使我在测试时(在真实设备和模拟器上)登录到游戏中心,查看排行榜时
您可以使用 1 行代码轻松提取轮廓分数,该代码对所有集群的分数进行平均,但是如何从轮廓分数的 scikit learn 实现中提取每个中间分数?我希望能够为每个集群单独提取相同的分数,而不仅仅是获得总
我正在用 JavaScript 和 HTML 制作一个在线游戏(一个非常简单的游戏,这是我的第一个游戏)。它工作正常,但有一个大问题。我希望每当单击特定图像时,都会将 10 添加到变量分数的值中。这是
我的 votes 表如下所示: id: integer vote: boolean voteable_id: integer voteable_type: string voter_id: integ
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 9 年前。 Improve this q
无法读取未定义的属性“分数”这是一个使用极小极大算法的井字游戏。这是我整个应用程序的笔。 https://codepen.io/MartinaMF/pen/LjNdNN $(document)
我有一个引用字典“dictA”,我需要将它(计算键和 vules 之间的相似度)与当场生成的 n 个字典进行比较。每个字典的长度相同。假设为了便于讨论,要与之比较的词典数量为 3:dictB、dict
1、计算F1-Score 对于二分类来说,假设batch size 大小为64的话,那么模型一个batch的输出应该是torch.size([64,2]),所以首先做的是得到这个二维矩阵的每一行的
我是一名优秀的程序员,十分优秀!