当我的代码运行单元测试时,效果非常好并显示:
test_bank.py ... [100%]
====================================================================== 3 passed in 0.02s =======================================================================
但是当发送我的代码时,我得到以下反馈:
Results for cs50/problems/2022/python/tests/bank generated by check50 v3.3.10
:) test_bank.py exist
:( correct bank.py passes all test_bank checks
expected exit code 0, not 1
:| test_bank catches bank.py with incorrect values
can't check until a frown turns upside down
:| test_bank catches bank.py without case-insensitivity
can't check until a frown turns upside down
:| test_bank catches bank.py not allowing for entire phrase
can't check until a frown turns upside down
您可以在下面看到我的代码:
银行.py
def main():
print(value(input("Hello: ")))
def value(greeting):
greeting = greeting.lower().strip()
bank_split = list(greeting)
greeting = ["h","e","l","l","o"]
if greeting[0] != bank_split[0]:
return("$100")
elif greeting[0:4] == bank_split[0:4]:
return("$0")
else:
return("$20")
if __name__ == "__main__":
main()
test_bank.py
from bank import value
def test_value_100():
assert value("What's up?") == "$100"
def test_value_20():
assert value("Hi") == "$20"
def test_value_0():
assert value("Hello") == "$0"
谢谢您的帮助!
我尝试运行 CS50 检查,尽管它的输出与我的 pytest 不同
感谢您花时间考虑我的主题。我也道歉;我没有正确阅读说明。
我需要返回一个整数值而不是字符串。
def main():
print(value(input("Hello: ")))
def value(greeting):
greeting = greeting.lower().strip()
bank_split = list(greeting)
greeting = ["h","e","l","l","o"]
if greeting[0] != bank_split[0]:
return(int(100))
elif greeting[0:4] == bank_split[0:4]:
return(int(0))
else:
return(int(20))
if __name__ == "__main__":
main()