首页 文章

Python函数请求输入不执行if语句 - 没有显示错误

提问于
浏览
0

我彻底搜索了我的问题的答案,但找不到任何可以解释我的结果的东西 . 我真的希望你们中的任何人都能指出我正确的方向 .


目前,我正在尝试使用Python 3编写基于文本的冒险游戏,以便更好地理解语言 .

在这样做时,我创建了一个函数,应该根据用户输入询问 userinputprint a specific statement . In case users inputinvalid 该函数应该 keep asking for input 直到它有效 .

Unfortunately the function only seems to keep asking for input, without ever executing the if/elif statements within the function. Due to no errors being shown I am currently at a loss as to why this is the case...


print("If You want to start the game, please enter 'start'." + "\n" +              
      "Otherwise please enter 'quit' in order to quit the game.")

startGame = True


def StartGame_int(answer):
    if answer.lower() == "start":
        startGame = False
        return "Welcome to Vahlderia!"
    elif answer.lower() == "quit":
        startGame = False
        return "Thank You for playing Vahlderia!" + "\n" + "You can now close
                the window."
    else:
        return "Please enter either 'r' to start or 'q' to quit the game."

def StartGame(): 
    answ = input("- ")
    StartGame_int(answ)


while startGame == True:
    StartGame()

1 回答

相关问题