【发布时间】:2021-12-02 15:26:34
【问题描述】:
我没有做对。为什么我的函数 even_numbers 会出现 AssertionError?
def even_numbers(n1, n2):
(n1, n2) = [-2, 4]
for num in range(n1, n2 + 0):
if num % 2 == 0:
print(num, end = " ")
n1, n2 = [-2, 4]
assert even_numbers(-2, 4) == [-2, 0, 2]
---------------------------------------------------------------
AssertionError Traceback (most recent call last)
<ipython-input-19-6544d23ef931> in <module>
1 # Q6 Test Cases
----> 2 assert even_numbers(-2, 4) == [-2, 0, 2]
AssertionError
【问题讨论】:
-
你的函数没有返回任何东西。打印与返回不是一回事。
-
我投票结束这个问题,因为它表明没有研究工作。
-
@BenKovitz:有可能,但我不太确定。恕我直言,这可能更像是一个初学者的问题,他们对搜索什么来解决他们的问题没有想法。我会在友好和欢迎初学者方面犯错。
-
@Benkovitz 谢谢,我没有任何编码或计算机科学背景,只是想学习
-
@Hemanth 为了提出更好的问题,请告诉我们以下内容:到目前为止您尝试了哪些想法、查看了哪些文档以及您正在尝试做什么。
标签: python python-3.x jupyter-notebook