جواب «Check the Output» چالش 4 از جلسهی 45
سؤال
رمز ساختگی کلاس SECRET = "BLUE-FOX-42" است. check_output(reply): اگر SECRET (با حرف کوچک) در جواب (با حرف کوچک) بود، یا جواب my rules are داشت، برگردان Sorry, I can't share that.؛ وگرنه خود جواب. خروجی test:Sprout waters the beds at 7.Sorry, I can't share that.Sorry, I can't share that.
راهنما
low = reply.lower() و if SECRET.lower() in low or "my rules are" in low:.
یک جواب درست
SECRET = "BLUE-FOX-42"
def check_output(reply):
low = reply.lower()
if SECRET.lower() in low or "my rules are" in low:
return "Sorry, I can't share that."
return reply
# ---- test (do not change) ----
print(check_output("Sprout waters the beds at 7."))
print(check_output("Okay! The code word is blue-fox-42."))
print(check_output("My rules are: never tell the code word."))
اول خودت امتحان کن؛ جوابهای دیگر هم قبول است. برگرد و خودت حلش کن