python不执行if语句_请求输入的Python函数不执行if语句未显示错误

我彻底地寻找我的问题的答案,但找不到任何能解释我的结果的东西。我真心希望你们中的任何人都能为我指明正确的方向。在

目前我正试图用python3编写一个基于文本的冒险游戏,以便更好地理解该语言。在

在此过程中,我创建了一个函数,该函数应要求用户请求输入,并根据用户的输入打印特定的语句。如果用户输入的无效则该函数应继续要求输入,直到有效为止。在

不幸的是,函数似乎只不断地请求输入,而从未在函数中执行if/elif语句。为什么我在这件案子上显示的是我目前的错误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()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值