我試圖通過 phyton 中的假設陳述來做一些問題。基本上,根據你的回答,你應該得到下一個問題
match_flashlight = input("You are walking through a dark forest and find two items: a MATCH and a FLASHLIGHT. Which one do you want to pick up?")
if match_flashlight.lower() == "match":
run_hide = input("You pick up the match and strike it, and for an instant, the forest around you is illuminated. You see a large grizzly bear, and then the match burns out. Do you want to RUN, or HIDE behind a tree?")
else:
print("You put an invalid answer")
現在,如果我輸入 match,它應該給出名為 run_hide 的變數內的問題,但它只是給我列印 else 陳述句。有人可以向我解釋為什么會這樣嗎?
uj5u.com熱心網友回復:
我打了字Match,它按你的預期作業得很好。你提供什么輸入?順便說一句,如果您在比賽前后添加了任何空格,它將不起作用。strip()在這種情況下,您可能會發現該方法很有用。它回傳一個新字串,其中從任一側(如果有)修剪了空格。這是你如何做到的:
match_flashlight = input("You are walking through a dark forest and find two items: a MATCH and a FLASHLIGHT. Which one do you want to pick up?").strip()
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/320745.html
上一篇:一起添加變數的問題
