2 回答

TA貢獻1780條經驗 獲得超5個贊
當你像那樣鏈接它們時你需要使用elif語句,否則輸入'i',if你擁有的第三條語句將為假并運行相關else語句:
## inventory var ##
inv=["torch"]
## inventory function ##
def ichk():
print(f" You are carrying{inv}")
return
##First room, links to a3##
def a2():
move=input("placeholder text.. You notice an exit to your 'east': ")
if move==("e"):
print("You exit to the east")
a3()
elif move==("i"):
ichk()
elif move==("q"):
print("You find nothing of value")
a2()
else:
print("You can't move in that direction")
a2()

TA貢獻2080條經驗 獲得超4個贊
在Python中,如果有多個條件語句,需要寫成:if,elif,elif,elif,....,else
## inventory var ##
inv=["torch"]
## inventory function ##
def ichk():
print(f" You are carrying{inv}")
return
##First room, links to a3##
def a2():
move=input("placeholder text.. You notice an exit to your 'east': ")
if move==("e"):
print("You exit to the east")
a3()
elif move==("i"):
ichk()
elif move==("q"):
print("You find nothing of value")
a2()
else:
print("You can't move in that direction")
a2()
添加回答
舉報