You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

拼写Bee测试评分代码优化:如何将数字评分转为字母等级

Convert Numeric Score to Letter Grade for Spelling Bee Test

Got it, let's tweak your function to return letter grades instead of a numeric total. Here's a straightforward way to do it:

First, we'll keep your existing logic to calculate the total number of correct words, then map that total to a letter grade using either conditional statements or a dictionary (I'll show both options so you can pick what works best for you).

Option 1: Using Conditional Statements (Easy to Read)

This is great if you want clear, explicit control over each grade threshold:

def how_eligible(essay):
    total = 0
    # Keep your existing scoring logic
    if 'hyperactive' in essay:
        total += 1
    if 'chrysanthemum' in essay:
        total += 1
    if 'onomatopoeia' in essay:
        total += 1
    if 'aardvark' in essay:
        total += 1
    if 'magnanimity' in essay:
        total += 1
    
    # Map total to letter grade
    if total == 5:
        return 'A'
    elif total == 4:
        return 'B'
    elif total == 3:
        return 'C'
    elif total == 2:
        return 'D'
    else:  # 0 or 1 correct words
        return 'F'

Option 2: Using a Dictionary (Cleaner for Simple Mappings)

If your grade-to-score mapping is straightforward, a dictionary makes the code more concise:

def how_eligible(essay):
    total = 0
    # Existing scoring logic (same as above)
    if 'hyperactive' in essay:
        total += 1
    if 'chrysanthemum' in essay:
        total += 1
    if 'onomatopoeia' in essay:
        total += 1
    if 'aardvark' in essay:
        total += 1
    if 'magnanimity' in essay:
        total += 1
    
    # Define score-to-grade mapping
    grade_map = {
        5: 'A',
        4: 'B',
        3: 'C',
        2: 'D',
        1: 'F',
        0: 'F'
    }
    return grade_map[total]

Customization Tip

You can easily adjust the grade thresholds if needed. For example, if you want a score of 1 to be a 'D' instead of 'F', just update the conditional or dictionary entries to match your desired grading scale.

内容的提问来源于stack exchange,提问作者KitKat G

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 11:07:50