我在 Codecademy 学习 Python。
有一个问题:
编写一个函数,shut_down,它接受一个参数(你可以使用任何你喜欢的东西;在这种情况下,我们将 s 用于字符串)。该shut_down函数应'Shutting down...'在获得'Yes'、'yes'或'YES'作为参数时以及'Shutdown aborted!'获得'No'、'no'或时返回'NO'。
针对这个问题,我写了这个:
def shut_down(n):
p=n.lower()
if p=="yes":
return "Shutting down..."
elif p=="no":
return "Shutdown aborted!"
但是,当我尝试运行它时,会出现以下错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'yes' is not defined*
请帮助我...我的代码中是否存在某种错误?