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

CS50P问题集5 test_bank问题:check50提示未以代码0退出

CS50P 问题集5代码检测异常求助

我正在学习CS50P课程,目前推进到问题集5的第二题。本地运行代码时程序能正常以退出码0结束,但用check50检测时,却提示代码未以退出码0退出。

我的功能代码(bank.py)如下:

def main():
    x = input("Greeting: ")
    print(value(x))

def value(greeting):
    greeting = greeting.lower().strip()
    if greeting.startswith("hello"):
        return "$0"
    elif greeting.startswith("h"):
        return "$20"
    else:
        return "$100"

if __name__ == "__main__":
    main()

测试该value函数的代码如下:

from bank import value

def test_hello():
    assert value("hello") == "$0"
    assert value("HELLO, mark") == "$0"

def test_h_words():
    assert value("hi") == "$20"
    assert value("howdy") == "$20"

def test_other_words():
    assert value("money") == "$100"
    assert value("food") == "$100"

def test_h_in_middle():
    assert value("she") == "$100"

def test_numbers():
    assert value("123") == "$100"

def test_symbols():
    assert value("!@#$%^&*") == "$100"

check50报错截图:
check50报错截图

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.11 04:12:33