你忘了写
s == "no"你的第一本
elif:
def shut_down(s): if s == "Yes" or s == "yes" or s == "YES": return "Shutting down..." elif s == "No" or "no" or "NO": # you forgot the s== in this line return "Shutdown aborted!" else: return "Sorry, I didn't understand you."
做这个:
def shut_down(s): if s == "Yes" or s == "yes" or s == "YES": return "Shutting down..." elif s == "No" or s == "no" or s == "NO": # fixed it return "Shutdown aborted!" else: return "Sorry, I didn't understand you."
这是因为:
elif s == "No" or "no" or "NO": #<---thiselif s == "No" or True or True: #<---is the same as this
由于这是公认的答案,因此我将详细介绍标准做法:不考虑大小写而比较字符串的约定(equalsIgnoreCase)的用法
.lower()如下:
elif s.lower() == "no":
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)