我有以下代码:
def begin_game():
print "You landed on planet and see three rooms."
door = int(raw_input("Pick number of door>>>"))
print "You approach and see that you need to enter password..."
password = raw_input("Enter your surname>>>")
if door == 1:
medical_room()
if door == 2:
library()
if door == 3:
basement()
else:
print "No room exists"
begin_game()
begin_game()
当我输入
door
数字时,我将完成medical_room
函数,但随后将执行else语句,并反复启动代码。我的问题是为什么要执行else语句它不应该停止if语句,在块内执行并停止吗?
最佳答案
您需要对第二个和第三个if语句使用elif
。else
只考虑它前面的语句。