gpt4 book ai didi

python - 如何在 python 的断言语句中使用小于等于

转载 作者:行者123 更新时间:2023-11-28 19:31:25 24 4
gpt4 key购买 nike

当我运行以下命令时:

growthRates = [3, 4, 5, 0, 3]
for each in growthRates:
print each
assert growthRates >= 0, 'Growth Rate is not between 0 and 100'
assert growthRates <= 100, 'Growth Rate is not between 0 and 100'

我得到:

3
Traceback (most recent call last):
File "ps4.py", line 132, in <module>
testNestEggVariable()
File "ps4.py", line 126, in testNestEggVariable
savingsRecord = nestEggVariable(salary, save, growthRates)
File "ps4.py", line 106, in nestEggVariable
assert growthRates <= 100, 'Growth Rate is not between 0 and 100'
AssertionError: Growth Rate is not between 0 and 100

这是为什么?

最佳答案

做:

assert each >= 0, 'Growth Rate is not between 0 and 100'

不是:

assert growthRates >= 0, 'Growth Rate is not between 0 and 100'

关于python - 如何在 python 的断言语句中使用小于等于,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3585443/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com