這是帶有可用選項的代碼。我不知道是怎么回事!
def start():
slow_print("""_
It's Monday, 9:33pm, August 4th, 2024.
You lay in the back of an old truck headed ...yada yada... emember the last time you were awake.
Enter (1) to observe your surroundings.
Enter (2) to scream your lungs out.
Enter (3) to climb out of the truck.
Enter (4) to hear what's going on around you.
_""", 1)
choice = input("--> ")
reset_console()
"1" 呼叫 start_observe() 就像它應該的那樣,但是 "2" 沒有呼叫 start_scream(),我很困惑!
if "1" in choice:
start_observe()
else:
start()
if "2" in choice:
start_scream()
else:
start()
if "3" in choice:
我唯一能想到的就是我沒有正確縮進,或者函式沒有按照它們需要的順序排列(雖然我測驗過,但不是這樣)。
更新,我將它更改為這種嵌套的 if 陳述句樣式并且它可以作業,如果我以這種方式更新會遇到任何進一步的問題嗎?
choice = input("--> ")
reset_console()
if "1" in choice:
start_observe()
else:
if "2" in choice:
start_scream()
else:
if "3" in choice:
start_climb()
else:
if "4" in choice:
start_hear()
else:
start()
另外,感謝路德的幫助!
更新#2:哈哈,好吧,我很笨。在我意識到 else: if equals elif 之后,我這樣做了。哈哈哈。
if "1" in choice:
start_observe()
elif "2" in choice:
start_scream()
elif "3" in choice:
start_climb()
elif "4" in choice:
start_hear()
else:
start()
uj5u.com熱心網友回復:
假設choice是'2',并且此代碼運行:
if "1" in choice: # False
start_observe()
else: # This clause runs.
start()
如果此代碼在start函式中,它將在代碼運行后開始遞回呼叫。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/469369.html
標籤:python-3.x 游戏开发
