小编Arn*_*Arn的帖子

函数和if - else在python中.Codeacademy

编写一个函数shut_down,它接受一个参数(你可以使用你喜欢的任何东西;在这种情况下,我们使用s作为字符串).当shut_down函数获得"是","是"或"是"作为参数时,应该返回"关闭...",并且"关闭已中止!" 当它变为"否","否"或"否"时.

如果它得到的不是那些输入,该函数应该返回"抱歉,我不明白你."

这是我的代码到目前为止......它的错误并说"不"不会返回"关机中止!"

def shut_down(s):
    if s == "Yes" or "yes" or "YES":
        return "Shutting down..."
    elif s == "No" or "no" or "NO":
        return "Shutdown aborted!"
    else:
        return "Sorry, I didn't understand you."
Run Code Online (Sandbox Code Playgroud)

python function

6
推荐指数
2
解决办法
4万
查看次数

标签 统计

function ×1

python ×1