dimanche 17 juin 2018

Python Function requesting input doesn't execute if statement - no error shown

I thoroughly searched for an answer to my question but couldn't find anything that would explain my results. I truly hope that anyone of you can point me in the right direction.


At the moment I am trying to program a text-based adventure game using Python 3 in order to better understand the language.

While doing so I created a function that should ask the user for input and print a specific statement depending on the users input. In case the users input is invalid the function should then keep asking for input until it is valid.

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()

Aucun commentaire:

Enregistrer un commentaire